Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 331633
Collapse All | Expand All

(-)src/org/eclipse/emf/facet/widgets/nattable/RowHeaderLayerStack.java (-1 / +2 lines)
Lines 22-28 Link Here
22
	private static final int DEFAULT_ROW_HEIGHT = 20;
22
	private static final int DEFAULT_ROW_HEIGHT = 20;
23
23
24
	public RowHeaderLayerStack(final IDataProvider dataProvider, final BodyLayerStack bodyLayer) {
24
	public RowHeaderLayerStack(final IDataProvider dataProvider, final BodyLayerStack bodyLayer) {
25
		DataLayer dataLayer = new DataLayer(dataProvider, RowHeaderLayerStack.DEFAULT_COLUMN_WIDTH, RowHeaderLayerStack.DEFAULT_ROW_HEIGHT);
25
		DataLayer dataLayer = new DataLayer(dataProvider, RowHeaderLayerStack.DEFAULT_COLUMN_WIDTH,
26
				RowHeaderLayerStack.DEFAULT_ROW_HEIGHT);
26
		RowHeaderLayer rowHeaderLayer = new RowHeaderLayer(dataLayer, bodyLayer,
27
		RowHeaderLayer rowHeaderLayer = new RowHeaderLayer(dataLayer, bodyLayer,
27
				bodyLayer.getSelectionLayer());
28
				bodyLayer.getSelectionLayer());
28
		setUnderlyingLayer(rowHeaderLayer);
29
		setUnderlyingLayer(rowHeaderLayer);
(-)src/org/eclipse/emf/facet/widgets/nattable/StyledColumnHeaderConfiguration.java (-3 / +6 lines)
Lines 79-85 Link Here
79
79
80
	private void addSelectedModeStyling(final IConfigRegistry configRegistry) {
80
	private void addSelectedModeStyling(final IConfigRegistry configRegistry) {
81
		ICellPainter selectedCellPainter = new BackgroundImagePainter(createCellPainter(),
81
		ICellPainter selectedCellPainter = new BackgroundImagePainter(createCellPainter(),
82
				StyledColumnHeaderConfiguration.SELECTED_BG_IMAGE, StyledColumnHeaderConfiguration.COLOR_GRAY);
82
				StyledColumnHeaderConfiguration.SELECTED_BG_IMAGE,
83
				StyledColumnHeaderConfiguration.COLOR_GRAY);
83
84
84
		// If sorting is enabled we still want the sort icon to be drawn.
85
		// If sorting is enabled we still want the sort icon to be drawn.
85
		SortableHeaderTextPainter selectedHeaderPainter = new SortableHeaderTextPainter(
86
		SortableHeaderTextPainter selectedHeaderPainter = new SortableHeaderTextPainter(
Lines 100-106 Link Here
100
	private void addNormalModeStyling(final IConfigRegistry configurationRegistry) {
101
	private void addNormalModeStyling(final IConfigRegistry configurationRegistry) {
101
102
102
		ICellPainter normalCellPainter = new BackgroundImagePainter(createCellPainter(),
103
		ICellPainter normalCellPainter = new BackgroundImagePainter(createCellPainter(),
103
				StyledColumnHeaderConfiguration.BG_IMAGE, StyledColumnHeaderConfiguration.COLOR_GRAY);
104
				StyledColumnHeaderConfiguration.BG_IMAGE,
105
				StyledColumnHeaderConfiguration.COLOR_GRAY);
104
106
105
		SortableHeaderTextPainter headerPainter = new SortableHeaderTextPainter(normalCellPainter,
107
		SortableHeaderTextPainter headerPainter = new SortableHeaderTextPainter(normalCellPainter,
106
				false);
108
				false);
Lines 116-122 Link Here
116
	private void addCornerStyling(final IConfigRegistry configurationRegistry) {
118
	private void addCornerStyling(final IConfigRegistry configurationRegistry) {
117
		// adds painting of the the gray triangle in the upper left corner
119
		// adds painting of the the gray triangle in the upper left corner
118
		ICellPainter cornerPainter = new BackgroundImagePainter(createCellPainter(),
120
		ICellPainter cornerPainter = new BackgroundImagePainter(createCellPainter(),
119
				StyledColumnHeaderConfiguration.BG_IMAGE, StyledColumnHeaderConfiguration.COLOR_GRAY) {
121
				StyledColumnHeaderConfiguration.BG_IMAGE,
122
				StyledColumnHeaderConfiguration.COLOR_GRAY) {
120
			@Override
123
			@Override
121
			public void paintCell(final LayerCell cell, final GC gc, final Rectangle rectangle,
124
			public void paintCell(final LayerCell cell, final GC gc, final Rectangle rectangle,
122
					final IConfigRegistry configRegistry) {
125
					final IConfigRegistry configRegistry) {
(-)src/org/eclipse/emf/facet/widgets/nattable/NatTableWidget.java (-142 / +32 lines)
Lines 56-75 Link Here
56
import net.sourceforge.nattable.util.GUIHelper;
56
import net.sourceforge.nattable.util.GUIHelper;
57
import net.sourceforge.nattable.viewport.ViewportLayer;
57
import net.sourceforge.nattable.viewport.ViewportLayer;
58
58
59
import org.eclipse.core.runtime.Platform;
60
import org.eclipse.emf.common.notify.Adapter;
59
import org.eclipse.emf.common.notify.Adapter;
61
import org.eclipse.emf.common.notify.Notification;
60
import org.eclipse.emf.common.notify.Notification;
62
import org.eclipse.emf.common.notify.impl.AdapterImpl;
61
import org.eclipse.emf.common.notify.impl.AdapterImpl;
63
import org.eclipse.emf.common.util.EList;
62
import org.eclipse.emf.common.util.EList;
64
import org.eclipse.emf.ecore.EAttribute;
63
import org.eclipse.emf.ecore.EAttribute;
65
import org.eclipse.emf.ecore.EClass;
64
import org.eclipse.emf.ecore.EClass;
66
import org.eclipse.emf.ecore.EClassifier;
67
import org.eclipse.emf.ecore.EDataType;
68
import org.eclipse.emf.ecore.EEnum;
65
import org.eclipse.emf.ecore.EEnum;
69
import org.eclipse.emf.ecore.EObject;
66
import org.eclipse.emf.ecore.EObject;
70
import org.eclipse.emf.ecore.EReference;
67
import org.eclipse.emf.ecore.EReference;
71
import org.eclipse.emf.ecore.EStructuralFeature;
68
import org.eclipse.emf.ecore.EStructuralFeature;
72
import org.eclipse.emf.ecore.EcorePackage;
73
import org.eclipse.emf.ecore.resource.Resource;
69
import org.eclipse.emf.ecore.resource.Resource;
74
import org.eclipse.emf.ecore.util.EcoreUtil;
70
import org.eclipse.emf.ecore.util.EcoreUtil;
75
import org.eclipse.emf.edit.ui.dnd.LocalTransfer;
71
import org.eclipse.emf.edit.ui.dnd.LocalTransfer;
Lines 80-88 Link Here
80
import org.eclipse.emf.facet.widgets.celleditors.IModelCellEditor;
76
import org.eclipse.emf.facet.widgets.celleditors.IModelCellEditor;
81
import org.eclipse.emf.facet.widgets.celleditors.IModelCellEditorValidator;
77
import org.eclipse.emf.facet.widgets.celleditors.IModelCellEditorValidator;
82
import org.eclipse.emf.facet.widgets.celleditors.INaryFeatureCellEditor;
78
import org.eclipse.emf.facet.widgets.celleditors.INaryFeatureCellEditor;
79
import org.eclipse.emf.facet.widgets.celleditors.ModelCellEditor;
83
import org.eclipse.emf.facet.widgets.celleditors.core.EEnumCellEditor;
80
import org.eclipse.emf.facet.widgets.celleditors.core.EEnumCellEditor;
84
import org.eclipse.emf.facet.widgets.celleditors.modelCellEditor.AbstractModelCellEditor;
81
import org.eclipse.emf.facet.widgets.celleditors.modelCellEditor.AbstractModelCellEditor;
85
import org.eclipse.emf.facet.widgets.celleditors.modelCellEditor.NaryFeatureCellEditor;
86
import org.eclipse.emf.facet.widgets.nattable.ColumnDescription.Type;
82
import org.eclipse.emf.facet.widgets.nattable.ColumnDescription.Type;
87
import org.eclipse.emf.facet.widgets.nattable.TableInput.ElementsDescription;
83
import org.eclipse.emf.facet.widgets.nattable.TableInput.ElementsDescription;
88
import org.eclipse.jface.action.MenuManager;
84
import org.eclipse.jface.action.MenuManager;
Lines 493-500 Link Here
493
			// not editable if no editing domain was provided
489
			// not editable if no editing domain was provided
494
			public void configureRegistry(final IConfigRegistry configRegistry) {
490
			public void configureRegistry(final IConfigRegistry configRegistry) {
495
				if (NatTableWidget.this.fTableInput.getEditingDomain() != null) {
491
				if (NatTableWidget.this.fTableInput.getEditingDomain() != null) {
496
					List<ModelCellEditorContainer<? extends AbstractModelCellEditor>> allCellEditorContainers = CellEditorsRegistry
497
							.getInstance().getAllCellEditors();
498
					for (int nColumn = 0; nColumn < NatTableWidget.this.fColumnDescriptions.size(); nColumn++) {
492
					for (int nColumn = 0; nColumn < NatTableWidget.this.fColumnDescriptions.size(); nColumn++) {
499
						ColumnDescription columnDescription = NatTableWidget.this.fColumnDescriptions
493
						ColumnDescription columnDescription = NatTableWidget.this.fColumnDescriptions
500
								.get(nColumn);
494
								.get(nColumn);
Lines 502-515 Link Here
502
						if (columnDescription.getType() == Type.ATTRIBUTE
496
						if (columnDescription.getType() == Type.ATTRIBUTE
503
								&& columnDescription.getAttribute().getEType() instanceof EEnum) {
497
								&& columnDescription.getAttribute().getEType() instanceof EEnum) {
504
							registerEnumCellEditor(configRegistry, (EEnum) columnDescription
498
							registerEnumCellEditor(configRegistry, (EEnum) columnDescription
505
									.getFeature().getEType(), columnLabelAccumulator,
499
									.getFeature().getEType(), columnLabelAccumulator, nColumn,
506
									allCellEditorContainers, nColumn, columnDescription);
500
									columnDescription);
507
						} else {
501
						} else {
508
							registerCellEditorForColumn(columnLabelAccumulator,
502
							registerCellEditorForColumn(columnLabelAccumulator, nColumn,
509
									allCellEditorContainers, nColumn, columnDescription);
503
									columnDescription);
510
						}
504
						}
511
					}
505
					}
512
506
507
					List<ModelCellEditorContainer<? extends AbstractModelCellEditor>> allCellEditorContainers = CellEditorsRegistry
508
							.getInstance().getAllCellEditors();
513
					for (ModelCellEditorContainer<? extends AbstractModelCellEditor> modelCellEditorContainer : allCellEditorContainers) {
509
					for (ModelCellEditorContainer<? extends AbstractModelCellEditor> modelCellEditorContainer : allCellEditorContainers) {
514
						registerCellEditor(modelCellEditorContainer, configRegistry);
510
						registerCellEditor(modelCellEditorContainer, configRegistry);
515
					}
511
					}
Lines 519-597 Link Here
519
	}
515
	}
520
516
521
	private void registerCellEditorForColumn(
517
	private void registerCellEditorForColumn(
522
			final ColumnOverrideLabelAccumulator columnLabelAccumulator,
518
			final ColumnOverrideLabelAccumulator columnLabelAccumulator, final int nColumn,
523
			final List<ModelCellEditorContainer<? extends AbstractModelCellEditor>> allCellEditorContainers,
519
			final ColumnDescription columnDescription) {
524
			final int nColumn, final ColumnDescription columnDescription) {
525
		if (columnDescription.getType() == ColumnDescription.Type.ATTRIBUTE
520
		if (columnDescription.getType() == ColumnDescription.Type.ATTRIBUTE
526
				|| columnDescription.getType() == ColumnDescription.Type.REFERENCE) {
521
				|| columnDescription.getType() == ColumnDescription.Type.REFERENCE) {
527
			EStructuralFeature feature = columnDescription.getFeature();
522
			EStructuralFeature feature = columnDescription.getFeature();
523
528
			if (!feature.isChangeable()) {
524
			if (!feature.isChangeable()) {
529
				return;
525
				return;
530
			}
526
			}
531
527
			ModelCellEditor selectedCellEditor = CellEditorsRegistry.getInstance()
532
			EClassifier eType = feature.getEType();
528
					.getCellEditorFor(feature.getEType(), feature.isMany());
533
534
			class CellEditor {
535
				private final String bundleName;
536
				private final String cellID;
537
538
				public CellEditor(final String bundleName, final String cellID) {
539
					this.bundleName = bundleName;
540
					this.cellID = cellID;
541
				}
542
543
				public String getBundleName() {
544
					return this.bundleName;
545
				}
546
547
				public String getCellID() {
548
					return this.cellID;
549
				}
550
			}
551
			List<CellEditor> cellEditors = new ArrayList<CellEditor>();
552
553
			for (ModelCellEditorContainer<? extends AbstractModelCellEditor> modelCellEditorContainer : allCellEditorContainers) {
554
				AbstractModelCellEditor modelCellEditor = modelCellEditorContainer
555
						.getModelCellEditor();
556
557
				if (feature.isMany() != (modelCellEditor instanceof NaryFeatureCellEditor)) {
558
					continue;
559
				}
560
561
				if (isSuperType(modelCellEditor.getCellType(), eType)) {
562
					cellEditors.add(new CellEditor(modelCellEditorContainer.getBundleName(),
563
							modelCellEditor.getCellId()));
564
				}
565
			}
566
567
			CellEditor selectedCellEditor = null;
568
			if (cellEditors.size() == 1) {
569
				selectedCellEditor = cellEditors.get(0);
570
			} else if (cellEditors.size() > 1) {
571
				boolean skippedDefault = false;
572
				for (CellEditor cellEditor : cellEditors) {
573
					// lower priority for
574
					// org.eclipse.emf.facet.widgets.celleditors.*
575
					if (cellEditor.getBundleName().startsWith(
576
							"org.eclipse.emf.facet.widgets.celleditors")) { //$NON-NLS-1$
577
						if (skippedDefault) {
578
							Logger.logError(
579
									"Several default cell editors are defined in EMF Facet for type: " //$NON-NLS-1$
580
											+ eType.getName(), Activator.getDefault());
581
							selectedCellEditor = cellEditor;
582
							break;
583
						}
584
						skippedDefault = true;
585
						continue;
586
					}
587
					if (selectedCellEditor != null) {
588
						Logger.logWarning("Several cell editors are defined for type: " //$NON-NLS-1$
589
								+ eType.getName(), Activator.getDefault());
590
						break;
591
					}
592
					selectedCellEditor = cellEditor;
593
				}
594
			}
595
529
596
			if (selectedCellEditor != null) {
530
			if (selectedCellEditor != null) {
597
				// register cell editor for this column
531
				// register cell editor for this column
Lines 599-634 Link Here
599
						selectedCellEditor.getCellID());
533
						selectedCellEditor.getCellID());
600
			} else {
534
			} else {
601
				Logger.logWarning(
535
				Logger.logWarning(
602
						"No cell editor defined for type: " + EcoreUtil.getURI(eType) + " (column " + nColumn + ")", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
536
						"No cell editor defined for type: " + EcoreUtil.getURI(feature.getEType()) + " (column " + nColumn + ")", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
603
						Activator.getDefault());
537
						Activator.getDefault());
604
			}
538
			}
605
		}
539
		}
606
	}
540
	}
607
541
608
	private boolean isSuperType(final EClassifier superType, final EClassifier subType) {
609
		if (superType == subType) {
610
			return true;
611
		}
612
613
		if (superType instanceof EClass && subType instanceof EClass) {
614
			// special case because isSuperTypeOf doesn't handle it
615
			if (superType == EcorePackage.eINSTANCE.getEObject()) {
616
				return true;
617
			}
618
619
			EClass superTypeEClass = (EClass) superType;
620
			EClass subTypeEClass = (EClass) subType;
621
			return superTypeEClass.isSuperTypeOf(subTypeEClass);
622
		}
623
624
		if (superType == EcorePackage.eINSTANCE.getEDataType() && subType instanceof EDataType) {
625
			// cf Bug 331539 - cell editor registered for type "EDataType"
626
			return true;
627
		}
628
629
		return false;
630
	}
631
632
	/**
542
	/**
633
	 * Registers a cell editor in the config registry
543
	 * Registers a cell editor in the config registry
634
	 * 
544
	 * 
Lines 639-650 Link Here
639
	 * @param nColumn
549
	 * @param nColumn
640
	 * @param columnDescription
550
	 * @param columnDescription
641
	 */
551
	 */
642
	private void registerEnumCellEditor(
552
	private void registerEnumCellEditor(final IConfigRegistry configRegistry, final EEnum eType,
643
			final IConfigRegistry configRegistry,
553
			final ColumnOverrideLabelAccumulator columnLabelAccumulator, final int nColumn,
644
			final EEnum eType,
554
			final ColumnDescription columnDescription) {
645
			final ColumnOverrideLabelAccumulator columnLabelAccumulator,
646
			final List<ModelCellEditorContainer<? extends AbstractModelCellEditor>> allCellEditorContainers,
647
			final int nColumn, final ColumnDescription columnDescription) {
648
		columnLabelAccumulator.registerColumnOverrides(nColumn,
555
		columnLabelAccumulator.registerColumnOverrides(nColumn,
649
				NatTableWidget.ENUM_CELLEDITOR_LABEL);
556
				NatTableWidget.ENUM_CELLEDITOR_LABEL);
650
		configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR,
557
		configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR,
Lines 659-709 Link Here
659
	private void registerCellEditor(
566
	private void registerCellEditor(
660
			final ModelCellEditorContainer<? extends AbstractModelCellEditor> modelCellEditorContainer,
567
			final ModelCellEditorContainer<? extends AbstractModelCellEditor> modelCellEditorContainer,
661
			final IConfigRegistry configRegistry) {
568
			final IConfigRegistry configRegistry) {
662
		AbstractModelCellEditor modelCellEditor = modelCellEditorContainer.getModelCellEditor();
663
		String className = modelCellEditor.getModelCellEditorImpl();
664
665
		Class<?> classInstance = null;
666
		try {
667
			classInstance = Platform.getBundle(modelCellEditorContainer.getBundleName()).loadClass(
668
					className);
669
		} catch (Exception e) {
670
			Logger.logError("Could not find class: " + className, //$NON-NLS-1$
671
					Activator.getDefault());
672
			return;
673
		}
674
569
675
		Object instance = null;
570
		ModelCellEditor cellEditor = new ModelCellEditor(modelCellEditorContainer.getBundleName(),
676
		try {
571
				modelCellEditorContainer.getModelCellEditor());
677
			instance = classInstance.newInstance();
572
		Object cellEditorImplementation = cellEditor.getCellEditorImplementation();
678
		} catch (Exception e) {
679
			Logger.logError("Could not instantiate class: " + className, //$NON-NLS-1$
680
					Activator.getDefault());
681
			return;
682
		}
683
573
684
		if (instance instanceof IModelCellEditor) {
574
		if (cellEditorImplementation instanceof IModelCellEditor) {
685
			IModelCellEditor modelCellEditorImpl = (IModelCellEditor) instance;
575
			IModelCellEditor modelCellEditorImpl = (IModelCellEditor) cellEditorImplementation;
686
576
687
			configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR,
577
			configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR,
688
					new NatTableCellEditorAdapter(modelCellEditorImpl,
578
					new NatTableCellEditorAdapter(modelCellEditorImpl,
689
							NatTableWidget.this.fColumnDescriptions), DisplayMode.NORMAL,
579
							NatTableWidget.this.fColumnDescriptions), DisplayMode.NORMAL,
690
					modelCellEditor.getCellId());
580
					cellEditor.getCellID());
691
			configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE,
581
			configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE,
692
					IEditableRule.ALWAYS_EDITABLE, DisplayMode.EDIT, modelCellEditor.getCellId());
582
					IEditableRule.ALWAYS_EDITABLE, DisplayMode.EDIT, cellEditor.getCellID());
693
		} else if (instance instanceof INaryFeatureCellEditor) {
583
		} else if (cellEditorImplementation instanceof INaryFeatureCellEditor) {
694
			INaryFeatureCellEditor modelCellEditorImpl = (INaryFeatureCellEditor) instance;
584
			INaryFeatureCellEditor modelCellEditorImpl = (INaryFeatureCellEditor) cellEditorImplementation;
695
585
696
			configRegistry.registerConfigAttribute(
586
			configRegistry.registerConfigAttribute(
697
					EditConfigAttributes.CELL_EDITOR,
587
					EditConfigAttributes.CELL_EDITOR,
698
					new NatTableNaryReferenceCellEditorAdapter(modelCellEditorImpl,
588
					new NatTableNaryReferenceCellEditorAdapter(modelCellEditorImpl,
699
							NatTableWidget.this.fColumnDescriptions, this.fTableInput
589
							NatTableWidget.this.fColumnDescriptions, this.fTableInput
700
									.getEditingDomain()), DisplayMode.NORMAL, modelCellEditor
590
									.getEditingDomain()), DisplayMode.NORMAL, cellEditor
701
							.getCellId());
591
							.getCellID());
702
			configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE,
592
			configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE,
703
					IEditableRule.ALWAYS_EDITABLE, DisplayMode.EDIT, modelCellEditor.getCellId());
593
					IEditableRule.ALWAYS_EDITABLE, DisplayMode.EDIT, cellEditor.getCellID());
704
			// disable automatic commit for INaryReferenceCellEditor
594
			// disable automatic commit for INaryReferenceCellEditor
705
			configRegistry.registerConfigAttribute(EditConfigAttributes.DATA_VALIDATOR,
595
			configRegistry.registerConfigAttribute(EditConfigAttributes.DATA_VALIDATOR,
706
					IDataValidator.NEVER_VALID, DisplayMode.EDIT, modelCellEditor.getCellId());
596
					IDataValidator.NEVER_VALID, DisplayMode.EDIT, cellEditor.getCellID());
707
		} else {
597
		} else {
708
			Logger.logError("Model cell editor implementation must be an instance of " //$NON-NLS-1$
598
			Logger.logError("Model cell editor implementation must be an instance of " //$NON-NLS-1$
709
					+ IModelCellEditor.class.getSimpleName() + " or " //$NON-NLS-1$
599
					+ IModelCellEditor.class.getSimpleName() + " or " //$NON-NLS-1$
Lines 711-721 Link Here
711
			return;
601
			return;
712
		}
602
		}
713
603
714
		if (instance instanceof IModelCellEditorValidator) {
604
		if (cellEditorImplementation instanceof IModelCellEditorValidator) {
715
			IModelCellEditorValidator modelCellEditorValidator = (IModelCellEditorValidator) instance;
605
			IModelCellEditorValidator modelCellEditorValidator = (IModelCellEditorValidator) cellEditorImplementation;
716
			configRegistry.registerConfigAttribute(EditConfigAttributes.DATA_VALIDATOR,
606
			configRegistry.registerConfigAttribute(EditConfigAttributes.DATA_VALIDATOR,
717
					new DataValidatorAdapter(modelCellEditorValidator), DisplayMode.EDIT,
607
					new DataValidatorAdapter(modelCellEditorValidator), DisplayMode.EDIT,
718
					modelCellEditor.getCellId());
608
					cellEditor.getCellID());
719
		}
609
		}
720
	}
610
	}
721
611
(-)src/org/eclipse/emf/facet/widgets/celleditors/CellEditorsRegistry.java (+80 lines)
Lines 17-26 Link Here
17
import org.eclipse.core.runtime.IConfigurationElement;
17
import org.eclipse.core.runtime.IConfigurationElement;
18
import org.eclipse.emf.common.util.EList;
18
import org.eclipse.emf.common.util.EList;
19
import org.eclipse.emf.common.util.URI;
19
import org.eclipse.emf.common.util.URI;
20
import org.eclipse.emf.ecore.EClass;
21
import org.eclipse.emf.ecore.EClassifier;
22
import org.eclipse.emf.ecore.EDataType;
20
import org.eclipse.emf.ecore.EObject;
23
import org.eclipse.emf.ecore.EObject;
24
import org.eclipse.emf.ecore.EcorePackage;
21
import org.eclipse.emf.ecore.resource.Resource;
25
import org.eclipse.emf.ecore.resource.Resource;
22
import org.eclipse.emf.ecore.resource.ResourceSet;
26
import org.eclipse.emf.ecore.resource.ResourceSet;
23
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
27
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
28
import org.eclipse.emf.ecore.util.EcoreUtil;
24
import org.eclipse.emf.facet.infra.common.core.internal.extensions.AbstractRegistry;
29
import org.eclipse.emf.facet.infra.common.core.internal.extensions.AbstractRegistry;
25
import org.eclipse.emf.facet.infra.common.core.logging.Logger;
30
import org.eclipse.emf.facet.infra.common.core.logging.Logger;
26
import org.eclipse.emf.facet.widgets.celleditors.modelCellEditor.AbstractModelCellEditor;
31
import org.eclipse.emf.facet.widgets.celleditors.modelCellEditor.AbstractModelCellEditor;
Lines 85-90 Link Here
85
		return allCellEditors;
90
		return allCellEditors;
86
	}
91
	}
87
92
93
	public ModelCellEditor getCellEditorFor(final EClassifier type, final boolean many) {
94
95
		List<CellEditorsRegistry.ModelCellEditorContainer<? extends AbstractModelCellEditor>> allCellEditorContainers = getAllCellEditors();
96
97
		List<ModelCellEditor> cellEditors = new ArrayList<ModelCellEditor>();
98
99
		for (ModelCellEditorContainer<? extends AbstractModelCellEditor> modelCellEditorContainer : allCellEditorContainers) {
100
			AbstractModelCellEditor modelCellEditor = modelCellEditorContainer.getModelCellEditor();
101
102
			if (many != (modelCellEditor instanceof NaryFeatureCellEditor)) {
103
				continue;
104
			}
105
106
			if (isSuperType(modelCellEditor.getCellType(), type)) {
107
				cellEditors.add(new ModelCellEditor(modelCellEditorContainer.getBundleName(),
108
						modelCellEditorContainer.getModelCellEditor()));
109
			}
110
		}
111
112
		ModelCellEditor selectedCellEditor = null;
113
		if (cellEditors.size() == 1) {
114
			selectedCellEditor = cellEditors.get(0);
115
		} else if (cellEditors.size() > 1) {
116
			boolean skippedDefault = false;
117
			for (ModelCellEditor cellEditor : cellEditors) {
118
				// lower priority for
119
				// org.eclipse.emf.facet.widgets.celleditors.*
120
				if (cellEditor.getBundleName().startsWith(
121
						"org.eclipse.emf.facet.widgets.celleditors")) { //$NON-NLS-1$
122
					if (skippedDefault) {
123
						Logger.logError(
124
								"Several default cell editors are defined in EMF Facet for type: " //$NON-NLS-1$
125
										+ EcoreUtil.getURI(type), Activator.getDefault());
126
						selectedCellEditor = cellEditor;
127
						break;
128
					}
129
					skippedDefault = true;
130
					continue;
131
				}
132
				if (selectedCellEditor != null) {
133
					Logger.logWarning("Several cell editors are defined for type: " //$NON-NLS-1$
134
							+ EcoreUtil.getURI(type), Activator.getDefault());
135
					break;
136
				}
137
				selectedCellEditor = cellEditor;
138
			}
139
		}
140
141
		return selectedCellEditor;
142
	}
143
144
	private boolean isSuperType(final EClassifier superType, final EClassifier subType) {
145
		if (superType == subType) {
146
			return true;
147
		}
148
149
		if (superType instanceof EClass && subType instanceof EClass) {
150
			// special case because isSuperTypeOf doesn't handle it
151
			if (superType == EcorePackage.eINSTANCE.getEObject()) {
152
				return true;
153
			}
154
155
			EClass superTypeEClass = (EClass) superType;
156
			EClass subTypeEClass = (EClass) subType;
157
			return superTypeEClass.isSuperTypeOf(subTypeEClass);
158
		}
159
160
		if (superType == EcorePackage.eINSTANCE.getEDataType() && subType instanceof EDataType) {
161
			// cf Bug 331539 - cell editor registered for type "EDataType"
162
			return true;
163
		}
164
165
		return false;
166
	}
167
88
	public List<CellEditorsRegistry.ModelCellEditorContainer<BasicCellEditor>> getBasicCellEditors() {
168
	public List<CellEditorsRegistry.ModelCellEditorContainer<BasicCellEditor>> getBasicCellEditors() {
89
		return this.basicCellEditors;
169
		return this.basicCellEditors;
90
	}
170
	}
(-)src/org/eclipse/emf/facet/widgets/celleditors/modelCellEditor/impl/NaryFeatureCellEditorImpl.java (-1 / +2 lines)
Lines 152-158 Link Here
152
		switch (featureID) {
152
		switch (featureID) {
153
		case ModelCellEditorPackage.NARY_FEATURE_CELL_EDITOR__NARY_FEATURE_CELL_EDITOR_IMPL:
153
		case ModelCellEditorPackage.NARY_FEATURE_CELL_EDITOR__NARY_FEATURE_CELL_EDITOR_IMPL:
154
			return NaryFeatureCellEditorImpl.NARY_FEATURE_CELL_EDITOR_IMPL_EDEFAULT == null ? this.naryFeatureCellEditorImpl != null
154
			return NaryFeatureCellEditorImpl.NARY_FEATURE_CELL_EDITOR_IMPL_EDEFAULT == null ? this.naryFeatureCellEditorImpl != null
155
					: !NaryFeatureCellEditorImpl.NARY_FEATURE_CELL_EDITOR_IMPL_EDEFAULT.equals(this.naryFeatureCellEditorImpl);
155
					: !NaryFeatureCellEditorImpl.NARY_FEATURE_CELL_EDITOR_IMPL_EDEFAULT
156
							.equals(this.naryFeatureCellEditorImpl);
156
		}
157
		}
157
		return super.eIsSet(featureID);
158
		return super.eIsSet(featureID);
158
	}
159
	}
(-)src/org/eclipse/emf/facet/widgets/celleditors/DefaultCommandFactory.java (+5 lines)
Lines 34-39 Link Here
34
		return SetCommand.create(domain, owner, feature, value);
34
		return SetCommand.create(domain, owner, feature, value);
35
	}
35
	}
36
36
37
	public Command createSetCommand(final EditingDomain domain, final Object owner,
38
			final Object feature, final Object value, final int index) {
39
		return SetCommand.create(domain, owner, feature, value, index);
40
	}
41
37
	public Command createMoveCommand(final EditingDomain domain, final Object owner,
42
	public Command createMoveCommand(final EditingDomain domain, final Object owner,
38
			final Object feature, final Object value, final int index) {
43
			final Object feature, final Object value, final int index) {
39
		return MoveCommand.create(domain, owner, feature, value, index);
44
		return MoveCommand.create(domain, owner, feature, value, index);
(-)src/org/eclipse/emf/facet/widgets/celleditors/ModelCellEditor.java (+80 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 CEA LIST.
3
 *
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *   Nicolas Bros (Mia-Software) - initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.emf.facet.widgets.celleditors;
13
14
import org.eclipse.core.runtime.Platform;
15
import org.eclipse.emf.facet.infra.common.core.logging.Logger;
16
import org.eclipse.emf.facet.widgets.celleditors.modelCellEditor.AbstractModelCellEditor;
17
18
public class ModelCellEditor {
19
	private final String bundleName;
20
	private final AbstractModelCellEditor modelCellEditor;
21
22
	public ModelCellEditor(final String bundleName, final AbstractModelCellEditor modelCellEditor) {
23
		this.bundleName = bundleName;
24
		this.modelCellEditor = modelCellEditor;
25
	}
26
27
	public String getBundleName() {
28
		return this.bundleName;
29
	}
30
31
	public String getCellID() {
32
		return this.modelCellEditor.getCellId();
33
	}
34
35
	public AbstractModelCellEditor getModelCellEditor() {
36
		return this.modelCellEditor;
37
	}
38
39
	public Object getCellEditorImplementation() {
40
		String className = this.modelCellEditor.getModelCellEditorImpl();
41
42
		Class<?> classInstance = null;
43
		try {
44
			classInstance = Platform.getBundle(this.bundleName).loadClass(className);
45
		} catch (Exception e) {
46
			Logger.logError("Could not find class: " + className, //$NON-NLS-1$
47
					Activator.getDefault());
48
			return null;
49
		}
50
51
		Object instance = null;
52
		try {
53
			instance = classInstance.newInstance();
54
		} catch (Exception e) {
55
			Logger.logError("Could not instantiate class: " + className, //$NON-NLS-1$
56
					Activator.getDefault());
57
			return null;
58
		}
59
		return instance;
60
	}
61
62
	@Override
63
	public boolean equals(final Object obj) {
64
		if (obj instanceof ModelCellEditor) {
65
			ModelCellEditor other = (ModelCellEditor) obj;
66
			return other.getCellID().equals(getCellID());
67
		}
68
		return false;
69
	}
70
71
	@Override
72
	public int hashCode() {
73
		return getCellID().hashCode();
74
	}
75
76
	@Override
77
	public String toString() {
78
		return getBundleName() + "#" + getCellID(); //$NON-NLS-1$
79
	}
80
}
(-)src/org/eclipse/emf/facet/widgets/celleditors/ui/ModelCellsEditingSupport.java (+155 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 CEA LIST.
3
 *
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *   Nicolas Bros (Mia-Software) - initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.emf.facet.widgets.celleditors.ui;
13
14
import java.util.List;
15
16
import org.eclipse.emf.common.command.Command;
17
import org.eclipse.emf.ecore.EObject;
18
import org.eclipse.emf.ecore.EStructuralFeature;
19
import org.eclipse.emf.edit.domain.EditingDomain;
20
import org.eclipse.emf.facet.widgets.celleditors.CellEditorsRegistry;
21
import org.eclipse.emf.facet.widgets.celleditors.CommandFactoriesRegistry;
22
import org.eclipse.emf.facet.widgets.celleditors.ICommandFactory;
23
import org.eclipse.emf.facet.widgets.celleditors.IModelCellEditHandler;
24
import org.eclipse.emf.facet.widgets.celleditors.IModelCellEditor;
25
import org.eclipse.emf.facet.widgets.celleditors.ModelCellEditor;
26
import org.eclipse.jface.viewers.CellEditor;
27
import org.eclipse.jface.viewers.ColumnViewer;
28
import org.eclipse.jface.viewers.EditingSupport;
29
import org.eclipse.swt.widgets.Composite;
30
import org.eclipse.swt.widgets.Control;
31
32
public class ModelCellsEditingSupport extends EditingSupport {
33
34
	private final EStructuralFeature feature;
35
	private IModelCellEditor cellEditor;
36
	private final EObject eObject;
37
	private final EditingDomain editingDomain;
38
	private final ColumnViewer columnViewer;
39
	private final Object newValuePlaceholder;
40
41
	public ModelCellsEditingSupport(final ColumnViewer columnViewer,
42
			final EStructuralFeature feature, final EObject eObject,
43
			final EditingDomain editingDomain, final Object newValuePlaceholder) {
44
		super(columnViewer);
45
		this.columnViewer = columnViewer;
46
		this.feature = feature;
47
		this.eObject = eObject;
48
		this.editingDomain = editingDomain;
49
		this.newValuePlaceholder = newValuePlaceholder;
50
		ModelCellEditor modelCellEditor = CellEditorsRegistry.getInstance().getCellEditorFor(
51
				this.feature.getEType(), false);
52
		Object cellEditorImplementation = modelCellEditor.getCellEditorImplementation();
53
		if (cellEditorImplementation instanceof IModelCellEditor) {
54
			this.cellEditor = (IModelCellEditor) cellEditorImplementation;
55
		} else {
56
			throw new IllegalStateException("cell editor " + modelCellEditor //$NON-NLS-1$
57
					+ " doesn't implement " + IModelCellEditor.class.getSimpleName()); //$NON-NLS-1$
58
		}
59
	}
60
61
	@Override
62
	protected CellEditor getCellEditor(final Object element) {
63
		return new CellEditor((Composite) this.columnViewer.getControl()) {
64
65
			private Control control;
66
67
			@Override
68
			protected void doSetValue(final Object value) {
69
				//
70
			}
71
72
			@Override
73
			protected void doSetFocus() {
74
				this.control.setFocus();
75
			}
76
77
			@Override
78
			protected Object doGetValue() {
79
				return null;
80
			}
81
82
			@Override
83
			protected Control createControl(final Composite parent) {
84
				IModelCellEditHandler editHandler = new IModelCellEditHandler() {
85
					public void commit() {
86
						Object value = ModelCellsEditingSupport.this.cellEditor.getValue();
87
						List<?> list = (List<?>) ModelCellsEditingSupport.this.eObject
88
								.eGet(ModelCellsEditingSupport.this.feature);
89
						int index = list.indexOf(element);
90
						if (index != -1
91
								|| element == ModelCellsEditingSupport.this.newValuePlaceholder) {
92
							changeValue(element, value, index);
93
						}
94
						ModelCellsEditingSupport.this.columnViewer.refresh();
95
						// dispose();
96
						close();
97
					}
98
				};
99
100
				Object originalValue = null;
101
				if (element != ModelCellsEditingSupport.this.newValuePlaceholder) {
102
					originalValue = element;
103
				}
104
105
				this.control = ModelCellsEditingSupport.this.cellEditor.activateCell(parent,
106
						originalValue, editHandler, ModelCellsEditingSupport.this.feature,
107
						ModelCellsEditingSupport.this.eObject);
108
				return this.control;
109
			}
110
111
			public void close() {
112
				deactivate();
113
				Control parentControl = ModelCellsEditingSupport.this.columnViewer.getControl();
114
				if (parentControl != null && !parentControl.isDisposed()) {
115
					parentControl.forceFocus();
116
				}
117
				dispose();
118
				// if (this.control != null && !this.control.isDisposed()) {
119
				// this.control.dispose();
120
				// }
121
			}
122
		};
123
		// return new TextCellEditor();
124
	}
125
126
	@Override
127
	protected boolean canEdit(final Object element) {
128
		return true;
129
	}
130
131
	@Override
132
	protected Object getValue(final Object element) {
133
		return element;
134
	}
135
136
	@Override
137
	protected void setValue(final Object element, final Object value) {
138
		// TODO Auto-generated method stub
139
	}
140
141
	private void changeValue(final Object oldValue, final Object newValue, final int index) {
142
		ICommandFactory commandFactory = CommandFactoriesRegistry.getInstance()
143
				.getCommandFactoryFor(this.editingDomain);
144
		if (oldValue == this.newValuePlaceholder) {
145
			Command addCommand = commandFactory.createAddCommand(this.editingDomain, this.eObject,
146
					this.feature, newValue);
147
			this.editingDomain.getCommandStack().execute(addCommand);
148
		} else {
149
			Command setCommand = commandFactory.createSetCommand(this.editingDomain, this.eObject,
150
					this.feature, newValue, index);
151
			this.editingDomain.getCommandStack().execute(setCommand);
152
		}
153
	}
154
155
}
(-)src/org/eclipse/emf/facet/widgets/celleditors/core/NaryAttributeCellEditor.java (+45 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 CEA LIST.
3
 *
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *   Nicolas Bros (Mia-Software) - initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.emf.facet.widgets.celleditors.core;
13
14
import org.eclipse.emf.ecore.EObject;
15
import org.eclipse.emf.ecore.EStructuralFeature;
16
import org.eclipse.emf.edit.domain.EditingDomain;
17
import org.eclipse.emf.facet.widgets.celleditors.INaryFeatureCellEditor;
18
import org.eclipse.emf.facet.widgets.celleditors.ui.NaryAttributeEditingDialog;
19
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.widgets.Composite;
21
import org.eclipse.swt.widgets.Control;
22
23
public class NaryAttributeCellEditor implements INaryFeatureCellEditor {
24
25
	public Control activateCell(final Composite parent, final EStructuralFeature feature,
26
			final EObject source, final EditingDomain editingDomain) {
27
		final Composite placeholderComposite = new Composite(parent, SWT.NONE);
28
		NaryAttributeEditingDialog naryAttributeEditingDialog = new NaryAttributeEditingDialog(
29
				parent.getShell(), feature, source, editingDomain) {
30
			@Override
31
			public boolean close() {
32
				placeholderComposite.dispose();
33
				return super.close();
34
			}
35
		};
36
		naryAttributeEditingDialog.open();
37
38
		return placeholderComposite;
39
	}
40
41
	public Object getValue() {
42
		throw new UnsupportedOperationException();
43
	}
44
45
}
(-)src/org/eclipse/emf/facet/widgets/celleditors/ui/EditingUtils.java (+84 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 CEA LIST.
3
 *
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *   Nicolas Bros (Mia-Software) - initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.emf.facet.widgets.celleditors.ui;
13
14
import java.util.Collection;
15
import java.util.List;
16
17
import org.eclipse.emf.common.command.Command;
18
import org.eclipse.emf.common.command.CompoundCommand;
19
import org.eclipse.emf.ecore.EObject;
20
import org.eclipse.emf.ecore.EStructuralFeature;
21
import org.eclipse.emf.edit.domain.EditingDomain;
22
import org.eclipse.emf.facet.widgets.celleditors.ICommandFactory;
23
24
public final class EditingUtils {
25
	private EditingUtils() {
26
		//
27
	}
28
29
	public static void moveElementsUp(final EObject eObject, final EStructuralFeature feature,
30
			final Collection<Object> elements, final ICommandFactory commandFactory,
31
			final EditingDomain editingDomain) {
32
		CompoundCommand compoundCommand = new CompoundCommand();
33
34
		List<?> list = (List<?>) eObject.eGet(feature);
35
36
		int minIndex = 0;
37
		for (Object element : elements) {
38
			final int index = list.indexOf(element);
39
40
			Command moveCommand = commandFactory.createMoveCommand(editingDomain, eObject, feature,
41
					element, Math.max(index - 1, minIndex++));
42
			compoundCommand.append(moveCommand);
43
		}
44
		editingDomain.getCommandStack().execute(compoundCommand);
45
		// int[] selectionIndices;
46
		// Arrays.sort(selectionIndices);
47
		// CompoundCommand compoundCommand = new CompoundCommand();
48
		// int minIndex = 0;
49
		// for(int index : selectionIndices) {
50
		// Command moveCommand = MoveCommand.create(editingDomain,
51
		// eObject,feature, index, Math.max(index - 1,
52
		// minIndex++));
53
		// compoundCommand.append(moveCommand);
54
		// }
55
		// editingDomain.getCommandStack().execute(compoundCommand);
56
	}
57
58
	public static void moveElementsDown(final EObject eObject, final EStructuralFeature feature,
59
			final Collection<Object> elements, final ICommandFactory commandFactory,
60
			final EditingDomain editingDomain) {
61
		Object value = eObject.eGet(feature);
62
		List<?> list = (List<?>) value;
63
64
		CompoundCommand compoundCommand = new CompoundCommand();
65
66
		// prevent the last two elements from swapping
67
		boolean canMove = !elements.contains(list.get(list.size() - 1));
68
		for (int i = list.size() - 2; i >= 0; i--) {
69
			final Object selectedObject = list.get(i);
70
			if (elements.contains(selectedObject)) {
71
				if (canMove) {
72
					Command moveCommand = commandFactory.createMoveCommand(editingDomain, eObject,
73
							feature, selectedObject, i + 1);
74
					compoundCommand.append(moveCommand);
75
				}
76
			} else {
77
				canMove = true;
78
			}
79
80
		}
81
		editingDomain.getCommandStack().execute(compoundCommand);
82
	}
83
84
}
(-)src/org/eclipse/emf/facet/widgets/celleditors/ui/AssignableValuesContentProvider.java (+78 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 CEA LIST.
3
 *
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *   Nicolas Bros (Mia-Software) - initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.emf.facet.widgets.celleditors.ui;
13
14
import java.util.ArrayList;
15
import java.util.List;
16
17
import org.eclipse.emf.common.notify.Notifier;
18
import org.eclipse.emf.common.util.TreeIterator;
19
import org.eclipse.emf.ecore.EClassifier;
20
import org.eclipse.emf.ecore.EObject;
21
import org.eclipse.emf.ecore.EStructuralFeature;
22
import org.eclipse.emf.ecore.resource.Resource;
23
import org.eclipse.emf.ecore.resource.ResourceSet;
24
import org.eclipse.jface.viewers.ITreeContentProvider;
25
import org.eclipse.jface.viewers.Viewer;
26
27
public class AssignableValuesContentProvider implements ITreeContentProvider {
28
	public Object[] getElements(final Object inputElement) {
29
		if (inputElement instanceof FeatureValuesInput) {
30
			FeatureValuesInput assignableValuesInput = (FeatureValuesInput) inputElement;
31
			EStructuralFeature feature = assignableValuesInput.getFeature();
32
			EClassifier eType = feature.getEType();
33
			EObject source = assignableValuesInput.getSource();
34
			List<?> featureValues = (List<?>) source.eGet(feature);
35
36
			// build a list of EObjects assignable to the EReference
37
			List<EObject> list = new ArrayList<EObject>();
38
			Resource eResource = source.eResource();
39
			if (eResource == null) {
40
				return new Object[0];
41
			}
42
			ResourceSet resourceSet = eResource.getResourceSet();
43
			TreeIterator<Notifier> allContents = resourceSet.getAllContents();
44
			while (allContents.hasNext()) {
45
				Notifier notifier = allContents.next();
46
				if (notifier instanceof EObject) {
47
					EObject eObject = (EObject) notifier;
48
					if (eType.isInstance(eObject)
49
							&& (!feature.isUnique() || !featureValues.contains(eObject))) {
50
						list.add(eObject);
51
					}
52
				}
53
			}
54
			return list.toArray();
55
		}
56
		throw new IllegalArgumentException(FeatureValuesInput.class.getSimpleName() + " expected"); //$NON-NLS-1$
57
	}
58
59
	public void dispose() {
60
		//
61
	}
62
63
	public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) {
64
		//
65
	}
66
67
	public Object[] getChildren(final Object parentElement) {
68
		return null;
69
	}
70
71
	public Object getParent(final Object element) {
72
		return null;
73
	}
74
75
	public boolean hasChildren(final Object element) {
76
		return false;
77
	}
78
}
(-)src/org/eclipse/emf/facet/widgets/celleditors/ui/NaryReferenceEditingDialog.java (-160 / +21 lines)
Lines 11-30 Link Here
11
 *******************************************************************************/
11
 *******************************************************************************/
12
package org.eclipse.emf.facet.widgets.celleditors.ui;
12
package org.eclipse.emf.facet.widgets.celleditors.ui;
13
13
14
import java.util.ArrayList;
15
import java.util.Iterator;
14
import java.util.Iterator;
16
import java.util.List;
15
import java.util.List;
17
16
18
import org.eclipse.emf.common.command.Command;
17
import org.eclipse.emf.common.command.Command;
19
import org.eclipse.emf.common.command.CompoundCommand;
18
import org.eclipse.emf.common.command.CompoundCommand;
20
import org.eclipse.emf.common.notify.Notifier;
21
import org.eclipse.emf.common.util.TreeIterator;
22
import org.eclipse.emf.ecore.EClassifier;
23
import org.eclipse.emf.ecore.EObject;
19
import org.eclipse.emf.ecore.EObject;
24
import org.eclipse.emf.ecore.EReference;
20
import org.eclipse.emf.ecore.EReference;
25
import org.eclipse.emf.ecore.EStructuralFeature;
21
import org.eclipse.emf.ecore.EStructuralFeature;
26
import org.eclipse.emf.ecore.resource.Resource;
27
import org.eclipse.emf.ecore.resource.ResourceSet;
28
import org.eclipse.emf.edit.domain.EditingDomain;
22
import org.eclipse.emf.edit.domain.EditingDomain;
29
import org.eclipse.emf.facet.widgets.CustomizableLabelProvider;
23
import org.eclipse.emf.facet.widgets.CustomizableLabelProvider;
30
import org.eclipse.emf.facet.widgets.celleditors.CommandFactoriesRegistry;
24
import org.eclipse.emf.facet.widgets.celleditors.CommandFactoriesRegistry;
Lines 36-42 Link Here
36
import org.eclipse.jface.viewers.IOpenListener;
30
import org.eclipse.jface.viewers.IOpenListener;
37
import org.eclipse.jface.viewers.IStructuredContentProvider;
31
import org.eclipse.jface.viewers.IStructuredContentProvider;
38
import org.eclipse.jface.viewers.IStructuredSelection;
32
import org.eclipse.jface.viewers.IStructuredSelection;
39
import org.eclipse.jface.viewers.ITreeContentProvider;
40
import org.eclipse.jface.viewers.ListViewer;
33
import org.eclipse.jface.viewers.ListViewer;
41
import org.eclipse.jface.viewers.OpenEvent;
34
import org.eclipse.jface.viewers.OpenEvent;
42
import org.eclipse.jface.viewers.TreeViewer;
35
import org.eclipse.jface.viewers.TreeViewer;
Lines 61-68 Link Here
61
/** A dialog to edit a multiplicity-many {@link EReference} */
54
/** A dialog to edit a multiplicity-many {@link EReference} */
62
public class NaryReferenceEditingDialog extends Dialog {
55
public class NaryReferenceEditingDialog extends Dialog {
63
56
64
	private static final int CUSTOMIZATIONS_TREE_WIDTH = 200;
57
	private static final int AVAILABLE_VALUES_TREE_WIDTH = 200;
65
	private static final int CUSTOMIZATIONS_TREE_HEIGHT = 250;
58
	private static final int AVAILABLE_VALUES_TREE_HEIGHT = 250;
66
	private static final int NUM_COLUMNS = 4;
59
	private static final int NUM_COLUMNS = 4;
67
	// this is a *tree* viewer because PatternFilter only supports Trees
60
	// this is a *tree* viewer because PatternFilter only supports Trees
68
	private TreeViewer fAvailableValuesTreeViewer;
61
	private TreeViewer fAvailableValuesTreeViewer;
Lines 79-157 Link Here
79
	private AssignableValuesContentProvider assignableValuesContentProvider;
72
	private AssignableValuesContentProvider assignableValuesContentProvider;
80
	private final ICommandFactory commandFactory;
73
	private final ICommandFactory commandFactory;
81
74
82
	private class FeatureValuesInput {
83
		private final EStructuralFeature feature;
84
		private final EObject source;
85
86
		public FeatureValuesInput(final EStructuralFeature feature, final EObject source) {
87
			this.feature = feature;
88
			this.source = source;
89
		}
90
91
		public EStructuralFeature getFeature() {
92
			return this.feature;
93
		}
94
95
		public EObject getSource() {
96
			return this.source;
97
		}
98
	}
99
100
	private class AssignableValuesContentProvider implements ITreeContentProvider {
101
		public Object[] getElements(final Object inputElement) {
102
			if (inputElement instanceof FeatureValuesInput) {
103
				FeatureValuesInput assignableValuesInput = (FeatureValuesInput) inputElement;
104
				EStructuralFeature feature = assignableValuesInput.getFeature();
105
				EClassifier eType = feature.getEType();
106
				EObject source = assignableValuesInput.getSource();
107
				List<?> featureValues = (List<?>) source.eGet(feature);
108
109
				// build a list of EObjects assignable to the EReference
110
				List<EObject> list = new ArrayList<EObject>();
111
				Resource eResource = source.eResource();
112
				if (eResource == null) {
113
					return new Object[0];
114
				}
115
				ResourceSet resourceSet = eResource.getResourceSet();
116
				TreeIterator<Notifier> allContents = resourceSet.getAllContents();
117
				while (allContents.hasNext()) {
118
					Notifier notifier = allContents.next();
119
					if (notifier instanceof EObject) {
120
						EObject eObject = (EObject) notifier;
121
						if (eType.isInstance(eObject)
122
								&& (!feature.isUnique() || !featureValues.contains(eObject))) {
123
							list.add(eObject);
124
						}
125
					}
126
				}
127
				return list.toArray();
128
			}
129
			throw new IllegalArgumentException(
130
					NaryReferenceEditingDialog.FeatureValuesInput.class.getSimpleName()
131
							+ " expected"); //$NON-NLS-1$
132
		}
133
134
		public void dispose() {
135
			//
136
		}
137
138
		public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) {
139
			//
140
		}
141
142
		public Object[] getChildren(final Object parentElement) {
143
			return null;
144
		}
145
146
		public Object getParent(final Object element) {
147
			return null;
148
		}
149
150
		public boolean hasChildren(final Object element) {
151
			return false;
152
		}
153
	}
154
155
	private class AssignedValuesContentProvider implements IStructuredContentProvider {
75
	private class AssignedValuesContentProvider implements IStructuredContentProvider {
156
		public Object[] getElements(final Object inputElement) {
76
		public Object[] getElements(final Object inputElement) {
157
			if (inputElement instanceof FeatureValuesInput) {
77
			if (inputElement instanceof FeatureValuesInput) {
Lines 161-169 Link Here
161
				List<?> list = (List<?>) source.eGet(feature);
81
				List<?> list = (List<?>) source.eGet(feature);
162
				return list.toArray();
82
				return list.toArray();
163
			}
83
			}
164
			throw new IllegalArgumentException(
84
			throw new IllegalArgumentException(FeatureValuesInput.class.getSimpleName()
165
					NaryReferenceEditingDialog.FeatureValuesInput.class.getSimpleName()
85
					+ " expected"); //$NON-NLS-1$
166
							+ " expected"); //$NON-NLS-1$
167
		}
86
		}
168
87
169
		public void dispose() {
88
		public void dispose() {
Lines 283-359 Link Here
283
202
284
	@SuppressWarnings("unchecked")
203
	@SuppressWarnings("unchecked")
285
	private void upButtonClicked() {
204
	private void upButtonClicked() {
286
287
		// int[] selectionIndices =
288
		// this.fFeatureValuesListViewer.getList().getSelectionIndices();
289
		// Arrays.sort(selectionIndices);
290
		//
291
		// CompoundCommand compoundCommand = new CompoundCommand();
292
		//
293
		// int minIndex = 0;
294
		// for(int index : selectionIndices) {
295
		// Command moveCommand = MoveCommand.create(this.editingDomain,
296
		// this.fEObject, this.fFeature, index, Math.max(index - 1,
297
		// minIndex++));
298
		// compoundCommand.append(moveCommand);
299
		// }
300
		// this.fFeatureValuesListViewer.refresh();
301
		// this.editingDomain.getCommandStack().execute(compoundCommand);
302
303
		final IStructuredSelection selection = (IStructuredSelection) this.fFeatureValuesListViewer
205
		final IStructuredSelection selection = (IStructuredSelection) this.fFeatureValuesListViewer
304
				.getSelection();
206
				.getSelection();
305
207
		EditingUtils.moveElementsUp(this.fEObject, this.fFeature, selection.toList(),
306
		CompoundCommand compoundCommand = new CompoundCommand();
208
				this.commandFactory, this.editingDomain);
307
308
		List<?> list = (List<?>) this.fEObject.eGet(this.fFeature);
309
310
		int minIndex = 0;
311
		for (final Iterator<EObject> it = selection.iterator(); it.hasNext();) {
312
			final EObject element = it.next();
313
314
			final int index = list.indexOf(element);
315
316
			Command moveCommand = this.commandFactory.createMoveCommand(this.editingDomain,
317
					this.fEObject, this.fFeature, element, Math.max(index - 1, minIndex++));
318
			compoundCommand.append(moveCommand);
319
		}
320
		this.editingDomain.getCommandStack().execute(compoundCommand);
321
		this.fFeatureValuesListViewer.refresh();
209
		this.fFeatureValuesListViewer.refresh();
322
	}
210
	}
323
211
324
	private void downButtonClicked() {
212
	private void downButtonClicked() {
325
		final IStructuredSelection selection = (IStructuredSelection) this.fFeatureValuesListViewer
213
		final IStructuredSelection selection = (IStructuredSelection) this.fFeatureValuesListViewer
326
				.getSelection();
214
				.getSelection();
327
		final ArrayList<EObject> selectedObjects = new ArrayList<EObject>();
215
		EditingUtils.moveElementsDown(this.fEObject, this.fFeature, selection.toList(),
328
		for (final Object selectedObject : selection.toArray()) {
216
				this.commandFactory, this.editingDomain);
329
			selectedObjects.add((EObject) selectedObject);
217
		this.fFeatureValuesListViewer.refresh();
330
		}
331
332
		Object value = this.fEObject.eGet(this.fFeature);
333
		if (value instanceof List<?>) {
334
			List<?> list = (List<?>) value;
335
336
			CompoundCommand compoundCommand = new CompoundCommand();
337
338
			// prevent the last two elements from swapping
339
			boolean canMove = !selectedObjects.contains(list.get(list.size() - 1));
340
			for (int i = list.size() - 2; i >= 0; i--) {
341
				final Object selectedEObject = list.get(i);
342
				if (selectedObjects.contains(selectedEObject)) {
343
					if (canMove) {
344
						Command moveCommand = this.commandFactory.createMoveCommand(
345
								this.editingDomain, this.fEObject, this.fFeature, selectedEObject,
346
								i + 1);
347
						compoundCommand.append(moveCommand);
348
					}
349
				} else {
350
					canMove = true;
351
				}
352
353
			}
354
			this.editingDomain.getCommandStack().execute(compoundCommand);
355
			this.fFeatureValuesListViewer.refresh();
356
		}
357
	}
218
	}
358
219
359
	@SuppressWarnings("unchecked")
220
	@SuppressWarnings("unchecked")
Lines 498-505 Link Here
498
359
499
		final Tree availableValuesTree = new Tree(choiceComposite, SWT.MULTI | SWT.BORDER);
360
		final Tree availableValuesTree = new Tree(choiceComposite, SWT.MULTI | SWT.BORDER);
500
		final GridData availableValuesGridData = new GridData();
361
		final GridData availableValuesGridData = new GridData();
501
		availableValuesGridData.widthHint = NaryReferenceEditingDialog.CUSTOMIZATIONS_TREE_WIDTH;
362
		availableValuesGridData.widthHint = NaryReferenceEditingDialog.AVAILABLE_VALUES_TREE_WIDTH;
502
		availableValuesGridData.heightHint = NaryReferenceEditingDialog.CUSTOMIZATIONS_TREE_HEIGHT;
363
		availableValuesGridData.heightHint = NaryReferenceEditingDialog.AVAILABLE_VALUES_TREE_HEIGHT;
503
		availableValuesGridData.horizontalAlignment = SWT.FILL;
364
		availableValuesGridData.horizontalAlignment = SWT.FILL;
504
		availableValuesGridData.verticalAlignment = SWT.FILL;
365
		availableValuesGridData.verticalAlignment = SWT.FILL;
505
		availableValuesGridData.grabExcessHorizontalSpace = true;
366
		availableValuesGridData.grabExcessHorizontalSpace = true;
Lines 613-630 Link Here
613
		valuesLabelGridData.verticalAlignment = SWT.FILL;
474
		valuesLabelGridData.verticalAlignment = SWT.FILL;
614
		featureLabel.setLayoutData(valuesLabelGridData);
475
		featureLabel.setLayoutData(valuesLabelGridData);
615
476
616
		final org.eclipse.swt.widgets.List loadedCustomizationsList = new org.eclipse.swt.widgets.List(
477
		final org.eclipse.swt.widgets.List availableValuesList = new org.eclipse.swt.widgets.List(
617
				featureComposite, SWT.MULTI | SWT.BORDER);
478
				featureComposite, SWT.MULTI | SWT.BORDER);
618
		final GridData loadedCustomizationsGridData = new GridData();
479
		final GridData availableValuesGridData = new GridData();
619
		loadedCustomizationsGridData.widthHint = NaryReferenceEditingDialog.CUSTOMIZATIONS_TREE_WIDTH;
480
		availableValuesGridData.widthHint = NaryReferenceEditingDialog.AVAILABLE_VALUES_TREE_WIDTH;
620
		loadedCustomizationsGridData.heightHint = NaryReferenceEditingDialog.CUSTOMIZATIONS_TREE_HEIGHT;
481
		availableValuesGridData.heightHint = NaryReferenceEditingDialog.AVAILABLE_VALUES_TREE_HEIGHT;
621
		loadedCustomizationsGridData.verticalAlignment = SWT.FILL;
482
		availableValuesGridData.verticalAlignment = SWT.FILL;
622
		loadedCustomizationsGridData.horizontalAlignment = SWT.FILL;
483
		availableValuesGridData.horizontalAlignment = SWT.FILL;
623
		loadedCustomizationsGridData.grabExcessHorizontalSpace = true;
484
		availableValuesGridData.grabExcessHorizontalSpace = true;
624
		loadedCustomizationsGridData.grabExcessVerticalSpace = true;
485
		availableValuesGridData.grabExcessVerticalSpace = true;
625
		loadedCustomizationsList.setLayoutData(loadedCustomizationsGridData);
486
		availableValuesList.setLayoutData(availableValuesGridData);
626
487
627
		this.fFeatureValuesListViewer = new ListViewer(loadedCustomizationsList);
488
		this.fFeatureValuesListViewer = new ListViewer(availableValuesList);
628
		this.fFeatureValuesListViewer.setContentProvider(new AssignedValuesContentProvider());
489
		this.fFeatureValuesListViewer.setContentProvider(new AssignedValuesContentProvider());
629
		this.fFeatureValuesListViewer.setLabelProvider(new CustomizableLabelProvider());
490
		this.fFeatureValuesListViewer.setLabelProvider(new CustomizableLabelProvider());
630
		this.fFeatureValuesListViewer
491
		this.fFeatureValuesListViewer
(-)src/org/eclipse/emf/facet/widgets/celleditors/ICommandFactory.java (+7 lines)
Lines 33-38 Link Here
33
	Command createSetCommand(EditingDomain domain, final Object owner, Object feature, Object value);
33
	Command createSetCommand(EditingDomain domain, final Object owner, Object feature, Object value);
34
34
35
	/**
35
	/**
36
	 * This creates a {@link SetCommand} to set the owner's feature to the
37
	 * specified value at the specified index.
38
	 */
39
	Command createSetCommand(EditingDomain domain, final Object owner, Object feature,
40
			Object value, int index);
41
42
	/**
36
	 * This creates a {@link MoveCommand} to move a particular value to a
43
	 * This creates a {@link MoveCommand} to move a particular value to a
37
	 * particular index in the specified feature of the owner. The feature will
44
	 * particular index in the specified feature of the owner. The feature will
38
	 * often be <code>null</code> because the domain will deduce it.
45
	 * often be <code>null</code> because the domain will deduce it.
(-)src/org/eclipse/emf/facet/widgets/celleditors/modelCellEditor/impl/BasicCellEditorImpl.java (-1 / +2 lines)
Lines 151-157 Link Here
151
		switch (featureID) {
151
		switch (featureID) {
152
		case ModelCellEditorPackage.BASIC_CELL_EDITOR__BASIC_CELL_EDITOR_IMPL:
152
		case ModelCellEditorPackage.BASIC_CELL_EDITOR__BASIC_CELL_EDITOR_IMPL:
153
			return BasicCellEditorImpl.BASIC_CELL_EDITOR_IMPL_EDEFAULT == null ? this.basicCellEditorImpl != null
153
			return BasicCellEditorImpl.BASIC_CELL_EDITOR_IMPL_EDEFAULT == null ? this.basicCellEditorImpl != null
154
					: !BasicCellEditorImpl.BASIC_CELL_EDITOR_IMPL_EDEFAULT.equals(this.basicCellEditorImpl);
154
					: !BasicCellEditorImpl.BASIC_CELL_EDITOR_IMPL_EDEFAULT
155
							.equals(this.basicCellEditorImpl);
155
		}
156
		}
156
		return super.eIsSet(featureID);
157
		return super.eIsSet(featureID);
157
	}
158
	}
(-)org.eclipse.emf.facet.widgets.celleditors.core.modelcelleditors (+3 lines)
Lines 6-9 Link Here
6
  <modelCellEditors xsi:type="modelCellEditor:NaryFeatureCellEditor" cellId="naryref_cell" naryFeatureCellEditorImpl="org.eclipse.emf.facet.widgets.celleditors.core.NaryReferenceCellEditor">
6
  <modelCellEditors xsi:type="modelCellEditor:NaryFeatureCellEditor" cellId="naryref_cell" naryFeatureCellEditorImpl="org.eclipse.emf.facet.widgets.celleditors.core.NaryReferenceCellEditor">
7
    <cellType xsi:type="ecore:EClass" href="http://www.eclipse.org/emf/2002/Ecore#//EObject"/>
7
    <cellType xsi:type="ecore:EClass" href="http://www.eclipse.org/emf/2002/Ecore#//EObject"/>
8
  </modelCellEditors>
8
  </modelCellEditors>
9
  <modelCellEditors xsi:type="modelCellEditor:NaryFeatureCellEditor" cellId="naryattr_cell" naryFeatureCellEditorImpl="org.eclipse.emf.facet.widgets.celleditors.core.NaryAttributeCellEditor">
10
    <cellType xsi:type="ecore:EClass" href="http://www.eclipse.org/emf/2002/Ecore#//EDataType"/>
11
  </modelCellEditors>
9
</modelCellEditor:ModelCellEditorDeclarations>
12
</modelCellEditor:ModelCellEditorDeclarations>
(-)src/org/eclipse/emf/facet/widgets/celleditors/Messages.java (+3 lines)
Lines 15-20 Link Here
15
15
16
public final class Messages extends NLS {
16
public final class Messages extends NLS {
17
	private static final String BUNDLE_NAME = "org.eclipse.emf.facet.widgets.celleditors.messages"; //$NON-NLS-1$
17
	private static final String BUNDLE_NAME = "org.eclipse.emf.facet.widgets.celleditors.messages"; //$NON-NLS-1$
18
	public static String NaryAttributeEditingDialog_add;
19
	public static String NaryAttributeEditingDialog_delete;
20
	public static String NaryAttributeEditingDialog_enterNewValuePlaceholder;
18
	public static String NaryReferenceEditingDialog_add;
21
	public static String NaryReferenceEditingDialog_add;
19
	public static String NaryReferenceEditingDialog_addAll;
22
	public static String NaryReferenceEditingDialog_addAll;
20
	public static String NaryReferenceEditingDialog_addAllTooltip;
23
	public static String NaryReferenceEditingDialog_addAllTooltip;
(-)src/org/eclipse/emf/facet/widgets/celleditors/modelCellEditor/impl/AbstractModelCellEditorImpl.java (-2 / +4 lines)
Lines 151-157 Link Here
151
		this.cellId = newCellId;
151
		this.cellId = newCellId;
152
		if (eNotificationRequired()) {
152
		if (eNotificationRequired()) {
153
			eNotify(new ENotificationImpl(this, Notification.SET,
153
			eNotify(new ENotificationImpl(this, Notification.SET,
154
					ModelCellEditorPackage.ABSTRACT_MODEL_CELL_EDITOR__CELL_ID, oldCellId, this.cellId));
154
					ModelCellEditorPackage.ABSTRACT_MODEL_CELL_EDITOR__CELL_ID, oldCellId,
155
					this.cellId));
155
		}
156
		}
156
	}
157
	}
157
158
Lines 232-238 Link Here
232
		case ModelCellEditorPackage.ABSTRACT_MODEL_CELL_EDITOR__CELL_TYPE:
233
		case ModelCellEditorPackage.ABSTRACT_MODEL_CELL_EDITOR__CELL_TYPE:
233
			return this.cellType != null;
234
			return this.cellType != null;
234
		case ModelCellEditorPackage.ABSTRACT_MODEL_CELL_EDITOR__CELL_ID:
235
		case ModelCellEditorPackage.ABSTRACT_MODEL_CELL_EDITOR__CELL_ID:
235
			return AbstractModelCellEditorImpl.CELL_ID_EDEFAULT == null ? this.cellId != null : !AbstractModelCellEditorImpl.CELL_ID_EDEFAULT.equals(this.cellId);
236
			return AbstractModelCellEditorImpl.CELL_ID_EDEFAULT == null ? this.cellId != null
237
					: !AbstractModelCellEditorImpl.CELL_ID_EDEFAULT.equals(this.cellId);
236
		}
238
		}
237
		return super.eIsSet(featureID);
239
		return super.eIsSet(featureID);
238
	}
240
	}
(-)src/org/eclipse/emf/facet/widgets/celleditors/ui/FeatureValuesInput.java (+33 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 CEA LIST.
3
 *
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *   Nicolas Bros (Mia-Software) - initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.emf.facet.widgets.celleditors.ui;
13
14
import org.eclipse.emf.ecore.EObject;
15
import org.eclipse.emf.ecore.EStructuralFeature;
16
17
public class FeatureValuesInput {
18
	private final EStructuralFeature feature;
19
	private final EObject source;
20
21
	public FeatureValuesInput(final EStructuralFeature feature, final EObject source) {
22
		this.feature = feature;
23
		this.source = source;
24
	}
25
26
	public EStructuralFeature getFeature() {
27
		return this.feature;
28
	}
29
30
	public EObject getSource() {
31
		return this.source;
32
	}
33
}
(-)src/org/eclipse/emf/facet/widgets/celleditors/messages.properties (-10 / +18 lines)
Lines 1-29 Link Here
1
NaryAttributeEditingDialog_delete=D&elete
2
NaryAttributeEditingDialog_enterNewValuePlaceholder=<enter new value>
3
###############################################################################
4
# Copyright (c) 2010 CEA
5
#
6
# All rights reserved. This program and the accompanying materials
7
# are made available under the terms of the Eclipse Public License v1.0
8
# which accompanies this distribution, and is available at
9
# http://www.eclipse.org/legal/epl-v10.html
10
#
11
# Contributors:
12
#   Nicolas Bros (Mia-Software) - initial API and implementation
13
###############################################################################
14
NaryAttributeEditingDialog_add=&Add
1
NaryReferenceEditingDialog_addAll=>>
15
NaryReferenceEditingDialog_addAll=>>
2
NaryReferenceEditingDialog_addAllTooltip=Add all
16
NaryReferenceEditingDialog_addAllTooltip=Add all
3
NaryReferenceEditingDialog_addTooltip=Add
17
NaryReferenceEditingDialog_addTooltip=Add
4
NaryReferenceEditingDialog_availableValues=Available values
18
NaryReferenceEditingDialog_availableValues=Available values
5
NaryReferenceEditingDialog_deleteElements=Delete elements?
19
NaryReferenceEditingDialog_deleteElements=Delete elements?
6
NaryReferenceEditingDialog_deleteElementsLong=Since the feature is composite, this will delete the selected element(s) from the model.
20
NaryReferenceEditingDialog_deleteElementsLong=Since the feature is composite, this will delete the selected element(s) from the model.
7
NaryReferenceEditingDialog_down=Down
21
NaryReferenceEditingDialog_down=&Down
8
NaryReferenceEditingDialog_featureIsComposite=The feature is composite. 
22
NaryReferenceEditingDialog_featureIsComposite=The feature is composite. 
9
NaryReferenceEditingDialog_moveElement=Move element?
23
NaryReferenceEditingDialog_moveElement=Move element?
10
NaryReferenceEditingDialog_remove=<
24
NaryReferenceEditingDialog_remove=&<
11
NaryReferenceEditingDialog_removeAll=<<
25
NaryReferenceEditingDialog_removeAll=<<
12
NaryReferenceEditingDialog_removeAllTooltip=Remove all
26
NaryReferenceEditingDialog_removeAllTooltip=Remove all
13
NaryReferenceEditingDialog_removeTooltip=Remove
27
NaryReferenceEditingDialog_removeTooltip=Remove
14
NaryReferenceEditingDialog_shellTitle=Edit {0} of {1}
28
NaryReferenceEditingDialog_shellTitle=Edit {0} of {1}
15
NaryReferenceEditingDialog_typeFilterText=type filter text
29
NaryReferenceEditingDialog_typeFilterText=type filter text
16
NaryReferenceEditingDialog_up=Up
30
NaryReferenceEditingDialog_up=&Up
17
NaryReferenceEditingDialog_values=Values
31
NaryReferenceEditingDialog_values=Values
18
NaryReferenceEditingDialog_valueWillBeMoved=The selected value will be moved from its previous parent.
32
NaryReferenceEditingDialog_valueWillBeMoved=The selected value will be moved from its previous parent.
19
NaryReferenceEditingDialog_valueWillBeMovedAndPreviousLost=The selected value will be moved from its previous parent and the previous value will be lost.
33
NaryReferenceEditingDialog_valueWillBeMovedAndPreviousLost=The selected value will be moved from its previous parent and the previous value will be lost.
20
###############################################################################
34
NaryReferenceEditingDialog_add=&>
21
# Copyright (c) 2010 CEA
22
#
23
#   Contributors:
24
#     Nicolas Bros (Mia-Software) - initial API and implementation
25
###############################################################################
26
NaryReferenceEditingDialog_add=>
27
UnaryReferenceCellEditorComposite_0=Invalid selection
35
UnaryReferenceCellEditorComposite_0=Invalid selection
28
UnaryReferenceCellEditorComposite_1=Please select an EObject
36
UnaryReferenceCellEditorComposite_1=Please select an EObject
29
UnaryReferenceCellEditorComposite_2=Select an EObject
37
UnaryReferenceCellEditorComposite_2=Select an EObject
(-)src/org/eclipse/emf/facet/widgets/celleditors/modelCellEditor/impl/ModelCellEditorPackageImpl.java (-23 / +50 lines)
Lines 269-282 Link Here
269
				ModelCellEditorPackage.MODEL_CELL_EDITOR_DECLARATIONS__MODEL_CELL_EDITORS);
269
				ModelCellEditorPackage.MODEL_CELL_EDITOR_DECLARATIONS__MODEL_CELL_EDITORS);
270
270
271
		this.abstractModelCellEditorEClass = createEClass(ModelCellEditorPackage.ABSTRACT_MODEL_CELL_EDITOR);
271
		this.abstractModelCellEditorEClass = createEClass(ModelCellEditorPackage.ABSTRACT_MODEL_CELL_EDITOR);
272
		createEReference(this.abstractModelCellEditorEClass, ModelCellEditorPackage.ABSTRACT_MODEL_CELL_EDITOR__CELL_TYPE);
272
		createEReference(this.abstractModelCellEditorEClass,
273
		createEAttribute(this.abstractModelCellEditorEClass, ModelCellEditorPackage.ABSTRACT_MODEL_CELL_EDITOR__CELL_ID);
273
				ModelCellEditorPackage.ABSTRACT_MODEL_CELL_EDITOR__CELL_TYPE);
274
		createEAttribute(this.abstractModelCellEditorEClass,
275
				ModelCellEditorPackage.ABSTRACT_MODEL_CELL_EDITOR__CELL_ID);
274
276
275
		this.basicCellEditorEClass = createEClass(ModelCellEditorPackage.BASIC_CELL_EDITOR);
277
		this.basicCellEditorEClass = createEClass(ModelCellEditorPackage.BASIC_CELL_EDITOR);
276
		createEAttribute(this.basicCellEditorEClass, ModelCellEditorPackage.BASIC_CELL_EDITOR__BASIC_CELL_EDITOR_IMPL);
278
		createEAttribute(this.basicCellEditorEClass,
279
				ModelCellEditorPackage.BASIC_CELL_EDITOR__BASIC_CELL_EDITOR_IMPL);
277
280
278
		this.unaryReferenceCellEditorEClass = createEClass(ModelCellEditorPackage.UNARY_REFERENCE_CELL_EDITOR);
281
		this.unaryReferenceCellEditorEClass = createEClass(ModelCellEditorPackage.UNARY_REFERENCE_CELL_EDITOR);
279
		createEAttribute(this.unaryReferenceCellEditorEClass,
282
		createEAttribute(
283
				this.unaryReferenceCellEditorEClass,
280
				ModelCellEditorPackage.UNARY_REFERENCE_CELL_EDITOR__UNARY_REFERENCE_CELL_EDITOR_IMPL);
284
				ModelCellEditorPackage.UNARY_REFERENCE_CELL_EDITOR__UNARY_REFERENCE_CELL_EDITOR_IMPL);
281
285
282
		this.naryFeatureCellEditorEClass = createEClass(ModelCellEditorPackage.NARY_FEATURE_CELL_EDITOR);
286
		this.naryFeatureCellEditorEClass = createEClass(ModelCellEditorPackage.NARY_FEATURE_CELL_EDITOR);
Lines 319-351 Link Here
319
		this.naryFeatureCellEditorEClass.getESuperTypes().add(getAbstractModelCellEditor());
323
		this.naryFeatureCellEditorEClass.getESuperTypes().add(getAbstractModelCellEditor());
320
324
321
		// Initialize classes and features; add operations and parameters
325
		// Initialize classes and features; add operations and parameters
322
		initEClass(this.modelCellEditorDeclarationsEClass, ModelCellEditorDeclarations.class,
326
		initEClass(
327
				this.modelCellEditorDeclarationsEClass,
328
				ModelCellEditorDeclarations.class,
323
				"ModelCellEditorDeclarations", !EPackageImpl.IS_ABSTRACT, !EPackageImpl.IS_INTERFACE, //$NON-NLS-1$
329
				"ModelCellEditorDeclarations", !EPackageImpl.IS_ABSTRACT, !EPackageImpl.IS_INTERFACE, //$NON-NLS-1$
324
				EPackageImpl.IS_GENERATED_INSTANCE_CLASS);
330
				EPackageImpl.IS_GENERATED_INSTANCE_CLASS);
325
		initEReference(getModelCellEditorDeclarations_ModelCellEditors(),
331
		initEReference(getModelCellEditorDeclarations_ModelCellEditors(),
326
				getAbstractModelCellEditor(), null, "modelCellEditors", null, 0, -1, //$NON-NLS-1$
332
				getAbstractModelCellEditor(), null, "modelCellEditors", null, 0, -1, //$NON-NLS-1$
327
				ModelCellEditorDeclarations.class, !EPackageImpl.IS_TRANSIENT, !EPackageImpl.IS_VOLATILE, EPackageImpl.IS_CHANGEABLE,
333
				ModelCellEditorDeclarations.class, !EPackageImpl.IS_TRANSIENT,
328
				EPackageImpl.IS_COMPOSITE, !EPackageImpl.IS_RESOLVE_PROXIES, !EPackageImpl.IS_UNSETTABLE, EPackageImpl.IS_UNIQUE, !EPackageImpl.IS_DERIVED,
334
				!EPackageImpl.IS_VOLATILE, EPackageImpl.IS_CHANGEABLE, EPackageImpl.IS_COMPOSITE,
329
				EPackageImpl.IS_ORDERED);
335
				!EPackageImpl.IS_RESOLVE_PROXIES, !EPackageImpl.IS_UNSETTABLE,
336
				EPackageImpl.IS_UNIQUE, !EPackageImpl.IS_DERIVED, EPackageImpl.IS_ORDERED);
330
337
331
		initEClass(this.abstractModelCellEditorEClass, AbstractModelCellEditor.class,
338
		initEClass(
339
				this.abstractModelCellEditorEClass,
340
				AbstractModelCellEditor.class,
332
				"AbstractModelCellEditor", EPackageImpl.IS_ABSTRACT, !EPackageImpl.IS_INTERFACE, EPackageImpl.IS_GENERATED_INSTANCE_CLASS); //$NON-NLS-1$
341
				"AbstractModelCellEditor", EPackageImpl.IS_ABSTRACT, !EPackageImpl.IS_INTERFACE, EPackageImpl.IS_GENERATED_INSTANCE_CLASS); //$NON-NLS-1$
333
		initEReference(getAbstractModelCellEditor_CellType(), this.ecorePackage.getEClassifier(), null,
342
		initEReference(
343
				getAbstractModelCellEditor_CellType(),
344
				this.ecorePackage.getEClassifier(),
345
				null,
334
				"cellType", null, 1, 1, AbstractModelCellEditor.class, !EPackageImpl.IS_TRANSIENT, !EPackageImpl.IS_VOLATILE, //$NON-NLS-1$
346
				"cellType", null, 1, 1, AbstractModelCellEditor.class, !EPackageImpl.IS_TRANSIENT, !EPackageImpl.IS_VOLATILE, //$NON-NLS-1$
335
				EPackageImpl.IS_CHANGEABLE, !EPackageImpl.IS_COMPOSITE, EPackageImpl.IS_RESOLVE_PROXIES, !EPackageImpl.IS_UNSETTABLE, EPackageImpl.IS_UNIQUE,
347
				EPackageImpl.IS_CHANGEABLE, !EPackageImpl.IS_COMPOSITE,
336
				!EPackageImpl.IS_DERIVED, EPackageImpl.IS_ORDERED);
348
				EPackageImpl.IS_RESOLVE_PROXIES, !EPackageImpl.IS_UNSETTABLE,
337
		initEAttribute(getAbstractModelCellEditor_CellId(), this.ecorePackage.getEString(), "cellId", //$NON-NLS-1$
349
				EPackageImpl.IS_UNIQUE, !EPackageImpl.IS_DERIVED, EPackageImpl.IS_ORDERED);
338
				null, 1, 1, AbstractModelCellEditor.class, !EPackageImpl.IS_TRANSIENT, !EPackageImpl.IS_VOLATILE,
350
		initEAttribute(
339
				EPackageImpl.IS_CHANGEABLE, !EPackageImpl.IS_UNSETTABLE, !EPackageImpl.IS_ID, EPackageImpl.IS_UNIQUE, !EPackageImpl.IS_DERIVED, EPackageImpl.IS_ORDERED);
351
				getAbstractModelCellEditor_CellId(),
352
				this.ecorePackage.getEString(),
353
				"cellId", //$NON-NLS-1$
354
				null, 1, 1, AbstractModelCellEditor.class, !EPackageImpl.IS_TRANSIENT,
355
				!EPackageImpl.IS_VOLATILE, EPackageImpl.IS_CHANGEABLE, !EPackageImpl.IS_UNSETTABLE,
356
				!EPackageImpl.IS_ID, EPackageImpl.IS_UNIQUE, !EPackageImpl.IS_DERIVED,
357
				EPackageImpl.IS_ORDERED);
340
358
341
		addEOperation(this.abstractModelCellEditorEClass, this.ecorePackage.getEString(),
359
		addEOperation(this.abstractModelCellEditorEClass, this.ecorePackage.getEString(),
342
				"getModelCellEditorImpl", 1, 1, EPackageImpl.IS_UNIQUE, EPackageImpl.IS_ORDERED); //$NON-NLS-1$
360
				"getModelCellEditorImpl", 1, 1, EPackageImpl.IS_UNIQUE, EPackageImpl.IS_ORDERED); //$NON-NLS-1$
343
361
344
		initEClass(this.basicCellEditorEClass, BasicCellEditor.class, "BasicCellEditor", !EPackageImpl.IS_ABSTRACT, //$NON-NLS-1$
362
		initEClass(this.basicCellEditorEClass, BasicCellEditor.class,
363
				"BasicCellEditor", !EPackageImpl.IS_ABSTRACT, //$NON-NLS-1$
345
				!EPackageImpl.IS_INTERFACE, EPackageImpl.IS_GENERATED_INSTANCE_CLASS);
364
				!EPackageImpl.IS_INTERFACE, EPackageImpl.IS_GENERATED_INSTANCE_CLASS);
346
		initEAttribute(getBasicCellEditor_BasicCellEditorImpl(), this.ecorePackage.getEString(),
365
		initEAttribute(
366
				getBasicCellEditor_BasicCellEditorImpl(),
367
				this.ecorePackage.getEString(),
347
				"basicCellEditorImpl", null, 1, 1, BasicCellEditor.class, !EPackageImpl.IS_TRANSIENT, //$NON-NLS-1$
368
				"basicCellEditorImpl", null, 1, 1, BasicCellEditor.class, !EPackageImpl.IS_TRANSIENT, //$NON-NLS-1$
348
				!EPackageImpl.IS_VOLATILE, EPackageImpl.IS_CHANGEABLE, !EPackageImpl.IS_UNSETTABLE, !EPackageImpl.IS_ID, EPackageImpl.IS_UNIQUE, !EPackageImpl.IS_DERIVED,
369
				!EPackageImpl.IS_VOLATILE, EPackageImpl.IS_CHANGEABLE, !EPackageImpl.IS_UNSETTABLE,
370
				!EPackageImpl.IS_ID, EPackageImpl.IS_UNIQUE, !EPackageImpl.IS_DERIVED,
349
				EPackageImpl.IS_ORDERED);
371
				EPackageImpl.IS_ORDERED);
350
372
351
		initEClass(this.unaryReferenceCellEditorEClass, UnaryReferenceCellEditor.class,
373
		initEClass(this.unaryReferenceCellEditorEClass, UnaryReferenceCellEditor.class,
Lines 353-367 Link Here
353
				EPackageImpl.IS_GENERATED_INSTANCE_CLASS);
375
				EPackageImpl.IS_GENERATED_INSTANCE_CLASS);
354
		initEAttribute(getUnaryReferenceCellEditor_UnaryReferenceCellEditorImpl(),
376
		initEAttribute(getUnaryReferenceCellEditor_UnaryReferenceCellEditorImpl(),
355
				this.ecorePackage.getEString(), "unaryReferenceCellEditorImpl", null, 1, 1, //$NON-NLS-1$
377
				this.ecorePackage.getEString(), "unaryReferenceCellEditorImpl", null, 1, 1, //$NON-NLS-1$
356
				UnaryReferenceCellEditor.class, !EPackageImpl.IS_TRANSIENT, !EPackageImpl.IS_VOLATILE, EPackageImpl.IS_CHANGEABLE,
378
				UnaryReferenceCellEditor.class, !EPackageImpl.IS_TRANSIENT,
357
				!EPackageImpl.IS_UNSETTABLE, !EPackageImpl.IS_ID, EPackageImpl.IS_UNIQUE, !EPackageImpl.IS_DERIVED, EPackageImpl.IS_ORDERED);
379
				!EPackageImpl.IS_VOLATILE, EPackageImpl.IS_CHANGEABLE, !EPackageImpl.IS_UNSETTABLE,
380
				!EPackageImpl.IS_ID, EPackageImpl.IS_UNIQUE, !EPackageImpl.IS_DERIVED,
381
				EPackageImpl.IS_ORDERED);
358
382
359
		initEClass(this.naryFeatureCellEditorEClass, NaryFeatureCellEditor.class,
383
		initEClass(
384
				this.naryFeatureCellEditorEClass,
385
				NaryFeatureCellEditor.class,
360
				"NaryFeatureCellEditor", !EPackageImpl.IS_ABSTRACT, !EPackageImpl.IS_INTERFACE, EPackageImpl.IS_GENERATED_INSTANCE_CLASS); //$NON-NLS-1$
386
				"NaryFeatureCellEditor", !EPackageImpl.IS_ABSTRACT, !EPackageImpl.IS_INTERFACE, EPackageImpl.IS_GENERATED_INSTANCE_CLASS); //$NON-NLS-1$
361
		initEAttribute(getNaryFeatureCellEditor_NaryFeatureCellEditorImpl(),
387
		initEAttribute(getNaryFeatureCellEditor_NaryFeatureCellEditorImpl(),
362
				this.ecorePackage.getEString(), "naryFeatureCellEditorImpl", null, 1, 1, //$NON-NLS-1$
388
				this.ecorePackage.getEString(), "naryFeatureCellEditorImpl", null, 1, 1, //$NON-NLS-1$
363
				NaryFeatureCellEditor.class, !EPackageImpl.IS_TRANSIENT, !EPackageImpl.IS_VOLATILE, EPackageImpl.IS_CHANGEABLE,
389
				NaryFeatureCellEditor.class, !EPackageImpl.IS_TRANSIENT, !EPackageImpl.IS_VOLATILE,
364
				!EPackageImpl.IS_UNSETTABLE, !EPackageImpl.IS_ID, EPackageImpl.IS_UNIQUE, !EPackageImpl.IS_DERIVED, EPackageImpl.IS_ORDERED);
390
				EPackageImpl.IS_CHANGEABLE, !EPackageImpl.IS_UNSETTABLE, !EPackageImpl.IS_ID,
391
				EPackageImpl.IS_UNIQUE, !EPackageImpl.IS_DERIVED, EPackageImpl.IS_ORDERED);
365
392
366
		// Create resource
393
		// Create resource
367
		createResource(ModelCellEditorPackage.eNS_URI);
394
		createResource(ModelCellEditorPackage.eNS_URI);
(-)src/org/eclipse/emf/facet/widgets/celleditors/modelCellEditor/ModelCellEditorPackage.java (-4 / +8 lines)
Lines 450-456 Link Here
450
		 * @see org.eclipse.emf.facet.widgets.celleditors.modelCellEditor.impl.ModelCellEditorPackageImpl#getModelCellEditorDeclarations()
450
		 * @see org.eclipse.emf.facet.widgets.celleditors.modelCellEditor.impl.ModelCellEditorPackageImpl#getModelCellEditorDeclarations()
451
		 * @generated
451
		 * @generated
452
		 */
452
		 */
453
		EClass MODEL_CELL_EDITOR_DECLARATIONS = ModelCellEditorPackage.eINSTANCE.getModelCellEditorDeclarations();
453
		EClass MODEL_CELL_EDITOR_DECLARATIONS = ModelCellEditorPackage.eINSTANCE
454
				.getModelCellEditorDeclarations();
454
455
455
		/**
456
		/**
456
		 * The meta object literal for the '<em><b>Model Cell Editors</b></em>'
457
		 * The meta object literal for the '<em><b>Model Cell Editors</b></em>'
Lines 472-478 Link Here
472
		 * @see org.eclipse.emf.facet.widgets.celleditors.modelCellEditor.impl.ModelCellEditorPackageImpl#getAbstractModelCellEditor()
473
		 * @see org.eclipse.emf.facet.widgets.celleditors.modelCellEditor.impl.ModelCellEditorPackageImpl#getAbstractModelCellEditor()
473
		 * @generated
474
		 * @generated
474
		 */
475
		 */
475
		EClass ABSTRACT_MODEL_CELL_EDITOR = ModelCellEditorPackage.eINSTANCE.getAbstractModelCellEditor();
476
		EClass ABSTRACT_MODEL_CELL_EDITOR = ModelCellEditorPackage.eINSTANCE
477
				.getAbstractModelCellEditor();
476
478
477
		/**
479
		/**
478
		 * The meta object literal for the '<em><b>Cell Type</b></em>' reference
480
		 * The meta object literal for the '<em><b>Cell Type</b></em>' reference
Lines 524-530 Link Here
524
		 * @see org.eclipse.emf.facet.widgets.celleditors.modelCellEditor.impl.ModelCellEditorPackageImpl#getUnaryReferenceCellEditor()
526
		 * @see org.eclipse.emf.facet.widgets.celleditors.modelCellEditor.impl.ModelCellEditorPackageImpl#getUnaryReferenceCellEditor()
525
		 * @generated
527
		 * @generated
526
		 */
528
		 */
527
		EClass UNARY_REFERENCE_CELL_EDITOR = ModelCellEditorPackage.eINSTANCE.getUnaryReferenceCellEditor();
529
		EClass UNARY_REFERENCE_CELL_EDITOR = ModelCellEditorPackage.eINSTANCE
530
				.getUnaryReferenceCellEditor();
528
531
529
		/**
532
		/**
530
		 * The meta object literal for the '
533
		 * The meta object literal for the '
Lines 546-552 Link Here
546
		 * @see org.eclipse.emf.facet.widgets.celleditors.modelCellEditor.impl.ModelCellEditorPackageImpl#getNaryFeatureCellEditor()
549
		 * @see org.eclipse.emf.facet.widgets.celleditors.modelCellEditor.impl.ModelCellEditorPackageImpl#getNaryFeatureCellEditor()
547
		 * @generated
550
		 * @generated
548
		 */
551
		 */
549
		EClass NARY_FEATURE_CELL_EDITOR = ModelCellEditorPackage.eINSTANCE.getNaryFeatureCellEditor();
552
		EClass NARY_FEATURE_CELL_EDITOR = ModelCellEditorPackage.eINSTANCE
553
				.getNaryFeatureCellEditor();
550
554
551
		/**
555
		/**
552
		 * The meta object literal for the '
556
		 * The meta object literal for the '
(-)src/org/eclipse/emf/facet/widgets/celleditors/ui/NaryAttributeEditingDialog.java (+464 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 CEA LIST.
3
 *
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *   Nicolas Bros (Mia-Software) - initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.emf.facet.widgets.celleditors.ui;
13
14
import java.util.Iterator;
15
import java.util.List;
16
17
import org.eclipse.emf.common.command.Command;
18
import org.eclipse.emf.common.command.CompoundCommand;
19
import org.eclipse.emf.ecore.EAttribute;
20
import org.eclipse.emf.ecore.EDataType;
21
import org.eclipse.emf.ecore.EObject;
22
import org.eclipse.emf.ecore.EStructuralFeature;
23
import org.eclipse.emf.edit.domain.EditingDomain;
24
import org.eclipse.emf.facet.widgets.CustomizableLabelProvider;
25
import org.eclipse.emf.facet.widgets.celleditors.CommandFactoriesRegistry;
26
import org.eclipse.emf.facet.widgets.celleditors.ICommandFactory;
27
import org.eclipse.emf.facet.widgets.celleditors.Messages;
28
import org.eclipse.jface.dialogs.Dialog;
29
import org.eclipse.jface.dialogs.IDialogConstants;
30
import org.eclipse.jface.viewers.ColumnLabelProvider;
31
import org.eclipse.jface.viewers.ISelection;
32
import org.eclipse.jface.viewers.IStructuredContentProvider;
33
import org.eclipse.jface.viewers.IStructuredSelection;
34
import org.eclipse.jface.viewers.LabelProvider;
35
import org.eclipse.jface.viewers.TableViewer;
36
import org.eclipse.jface.viewers.TableViewerColumn;
37
import org.eclipse.jface.viewers.Viewer;
38
import org.eclipse.osgi.util.NLS;
39
import org.eclipse.swt.SWT;
40
import org.eclipse.swt.events.ControlEvent;
41
import org.eclipse.swt.events.ControlListener;
42
import org.eclipse.swt.events.KeyAdapter;
43
import org.eclipse.swt.events.KeyEvent;
44
import org.eclipse.swt.events.SelectionAdapter;
45
import org.eclipse.swt.events.SelectionEvent;
46
import org.eclipse.swt.graphics.Color;
47
import org.eclipse.swt.graphics.Image;
48
import org.eclipse.swt.layout.GridData;
49
import org.eclipse.swt.layout.GridLayout;
50
import org.eclipse.swt.widgets.Button;
51
import org.eclipse.swt.widgets.Composite;
52
import org.eclipse.swt.widgets.Control;
53
import org.eclipse.swt.widgets.Display;
54
import org.eclipse.swt.widgets.Event;
55
import org.eclipse.swt.widgets.Label;
56
import org.eclipse.swt.widgets.Listener;
57
import org.eclipse.swt.widgets.Shell;
58
import org.eclipse.swt.widgets.Table;
59
import org.eclipse.swt.widgets.TableColumn;
60
61
/** A dialog to edit a multiplicity-many {@link EAttribute} */
62
public class NaryAttributeEditingDialog extends Dialog {
63
64
	private static final int LIST_WIDTH = 200;
65
	private static final int LIST_HEIGHT = 250;
66
	private static final int NUM_COLUMNS = 2;
67
	private TableViewer fFeatureValuesTableViewer;
68
	private Button fAddButton;
69
	private Button fRemoveButton;
70
	private Button fUpButton;
71
	private Button fDownButton;
72
	private final EStructuralFeature fFeature;
73
	private final EObject fEObject;
74
	private final EditingDomain editingDomain;
75
	private final ICommandFactory commandFactory;
76
77
	private boolean bAddingValue = false;
78
79
	public boolean isAddingValue() {
80
		return this.bAddingValue;
81
	}
82
83
	private final Object newValuePlaceholder = new Object();
84
85
	private class AssignedValuesContentProvider implements IStructuredContentProvider {
86
		public Object[] getElements(final Object inputElement) {
87
			if (inputElement instanceof FeatureValuesInput) {
88
				FeatureValuesInput valuesInput = (FeatureValuesInput) inputElement;
89
				EStructuralFeature feature = valuesInput.getFeature();
90
				EObject source = valuesInput.getSource();
91
				List<?> list = (List<?>) source.eGet(feature);
92
				// add a temporary cell when editing
93
				if (isAddingValue()) {
94
					Object[] result = new Object[list.size() + 1];
95
					int i = 0;
96
					for (Object object : list) {
97
						result[i++] = object;
98
					}
99
					result[i] = NaryAttributeEditingDialog.this.newValuePlaceholder;
100
					return result;
101
				}
102
				return list.toArray();
103
			}
104
			throw new IllegalArgumentException(FeatureValuesInput.class.getSimpleName()
105
					+ " expected"); //$NON-NLS-1$
106
		}
107
108
		public void dispose() {
109
			//
110
		}
111
112
		public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) {
113
			//
114
		}
115
	}
116
117
	private final ColumnLabelProvider labelProvider = new ColumnLabelProvider() {
118
		private final LabelProvider delegateLabelProvider = new CustomizableLabelProvider();
119
120
		@Override
121
		public Image getImage(final Object element) {
122
			return this.delegateLabelProvider.getImage(element);
123
		}
124
125
		@Override
126
		public String getText(final Object element) {
127
			if (element == NaryAttributeEditingDialog.this.newValuePlaceholder) {
128
				return Messages.NaryAttributeEditingDialog_enterNewValuePlaceholder;
129
			}
130
			return this.delegateLabelProvider.getText(element);
131
		}
132
133
		@Override
134
		public Color getForeground(final Object element) {
135
			if (element == NaryAttributeEditingDialog.this.newValuePlaceholder) {
136
				return Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY);
137
			}
138
			return null;
139
		}
140
	};
141
142
	/**
143
	 * @param parent
144
	 *            the parent {@link Shell}
145
	 * @param feature
146
	 *            the feature to edit
147
	 * @param eObject
148
	 *            the {@link EObject} on which the feature must be edited
149
	 * @param editingDomain
150
	 *            the {@link EditingDomain} through which all editing is done
151
	 */
152
	public NaryAttributeEditingDialog(final Shell parent, final EStructuralFeature feature,
153
			final EObject eObject, final EditingDomain editingDomain) {
154
		super(parent);
155
		if (!(feature.getEType() instanceof EDataType)) {
156
			throw new IllegalArgumentException("feature type must be EDataType"); //$NON-NLS-1$
157
		}
158
159
		this.fFeature = feature;
160
		this.fEObject = eObject;
161
		this.editingDomain = editingDomain;
162
		this.commandFactory = CommandFactoriesRegistry.getInstance().getCommandFactoryFor(
163
				this.editingDomain);
164
	}
165
166
	@Override
167
	protected void configureShell(final Shell shell) {
168
		super.configureShell(shell);
169
		shell.setText(NLS.bind(Messages.NaryReferenceEditingDialog_shellTitle,
170
				this.fFeature.getName(), this.fEObject.eClass().getName()));
171
		// prevent Escape or Enter from closing the dialog
172
		// when a cell editor is active
173
		shell.addListener(SWT.Traverse, new Listener() {
174
			public void handleEvent(final Event e) {
175
				if ((e.detail == SWT.TRAVERSE_ESCAPE || e.detail == SWT.TRAVERSE_RETURN)
176
						&& NaryAttributeEditingDialog.this.fFeatureValuesTableViewer
177
								.isCellEditorActive()) {
178
					e.doit = false;
179
				}
180
			}
181
		});
182
	}
183
184
	@Override
185
	protected Control createDialogArea(final Composite parent) {
186
		final Composite contents = (Composite) super.createDialogArea(parent);
187
188
		final GridLayout contentsGridLayout = (GridLayout) contents.getLayout();
189
		contentsGridLayout.numColumns = NaryAttributeEditingDialog.NUM_COLUMNS;
190
191
		final GridData contentsGridData = (GridData) contents.getLayoutData();
192
		contentsGridData.horizontalAlignment = SWT.FILL;
193
		contentsGridData.verticalAlignment = SWT.FILL;
194
195
		createValuesPane(contents);
196
		createButtonsPane(contents);
197
198
		// this.fFeatureValuesTableViewer.addOpenListener(new IOpenListener() {
199
		// public void open(final OpenEvent event) {
200
		// editSelectedElement();
201
		// }
202
		// });
203
204
		this.fUpButton.addSelectionListener(new SelectionAdapter() {
205
			@Override
206
			public void widgetSelected(final SelectionEvent event) {
207
				upButtonClicked();
208
			}
209
		});
210
211
		this.fDownButton.addSelectionListener(new SelectionAdapter() {
212
			@Override
213
			public void widgetSelected(final SelectionEvent event) {
214
				downButtonClicked();
215
			}
216
		});
217
218
		this.fAddButton.addSelectionListener(new SelectionAdapter() {
219
			@Override
220
			public void widgetSelected(final SelectionEvent event) {
221
				addButtonClicked();
222
			}
223
		});
224
225
		this.fRemoveButton.addSelectionListener(new SelectionAdapter() {
226
			@Override
227
			public void widgetSelected(final SelectionEvent event) {
228
				removeButtonClicked();
229
			}
230
		});
231
232
		return contents;
233
	}
234
235
	@SuppressWarnings("unchecked")
236
	private void upButtonClicked() {
237
		final IStructuredSelection selection = (IStructuredSelection) this.fFeatureValuesTableViewer
238
				.getSelection();
239
240
		EditingUtils.moveElementsUp(this.fEObject, this.fFeature, selection.toList(),
241
				this.commandFactory, this.editingDomain);
242
243
		this.fFeatureValuesTableViewer.refresh();
244
	}
245
246
	@SuppressWarnings("unchecked")
247
	private void downButtonClicked() {
248
		final IStructuredSelection selection = (IStructuredSelection) this.fFeatureValuesTableViewer
249
				.getSelection();
250
251
		EditingUtils.moveElementsDown(this.fEObject, this.fFeature, selection.toList(),
252
				this.commandFactory, this.editingDomain);
253
254
		this.fFeatureValuesTableViewer.refresh();
255
	}
256
257
	private void addButtonClicked() {
258
		this.bAddingValue = true;
259
		// EDataType dataType = (EDataType) this.fFeature.getEType();
260
		// Object defaultValue = dataType.getDefaultValue();
261
		// if (dataType == EcorePackage.eINSTANCE.getEString()) {
262
		// defaultValue = "";
263
		// }
264
		// Command addCommand =
265
		// this.commandFactory.createAddCommand(this.editingDomain,
266
		// this.fEObject, this.fFeature, defaultValue);
267
		// this.editingDomain.getCommandStack().execute(addCommand);
268
		refresh();
269
		// this.fFeatureValuesTableViewer.setSelection(new
270
		// StructuredSelection(this.tempCellForNewValue),
271
		// true);
272
		this.fFeatureValuesTableViewer.editElement(this.newValuePlaceholder, 0);
273
	}
274
275
	@SuppressWarnings("unchecked")
276
	private void removeButtonClicked() {
277
		final IStructuredSelection selection = (IStructuredSelection) this.fFeatureValuesTableViewer
278
				.getSelection();
279
280
		CompoundCommand compoundCommand = new CompoundCommand();
281
282
		List<?> list = (List<?>) this.fEObject.eGet(this.fFeature);
283
284
		for (final Iterator<Object> it = selection.iterator(); it.hasNext();) {
285
			final Object element = it.next();
286
287
			if (list.contains(element)) {
288
				Command removeCommand = this.commandFactory.createRemoveCommand(this.editingDomain,
289
						this.fEObject, this.fFeature, element);
290
				compoundCommand.append(removeCommand);
291
			}
292
		}
293
		this.editingDomain.getCommandStack().execute(compoundCommand);
294
		refresh();
295
	}
296
297
	private void spacer(final Composite parent) {
298
		@SuppressWarnings("unused")
299
		Label label = new Label(parent, SWT.NONE);
300
	}
301
302
	private void createButtonsPane(final Composite contents) {
303
		final Composite buttonsComposite = new Composite(contents, SWT.NONE);
304
		final GridData buttonsCompositeGridData = new GridData();
305
		buttonsCompositeGridData.verticalAlignment = SWT.FILL;
306
		buttonsCompositeGridData.horizontalAlignment = SWT.FILL;
307
		buttonsComposite.setLayoutData(buttonsCompositeGridData);
308
		buttonsComposite.setLayout(new GridLayout());
309
310
		// spacer
311
		spacer(buttonsComposite);
312
313
		this.fAddButton = new Button(buttonsComposite, SWT.PUSH);
314
		this.fAddButton.setText(Messages.NaryAttributeEditingDialog_add);
315
		final GridData addButtonGridData = new GridData();
316
		addButtonGridData.verticalAlignment = SWT.FILL;
317
		addButtonGridData.horizontalAlignment = SWT.FILL;
318
		// addButtonGridData.widthHint = 70;
319
		this.fAddButton.setLayoutData(addButtonGridData);
320
321
		this.fRemoveButton = new Button(buttonsComposite, SWT.PUSH);
322
		this.fRemoveButton.setText(Messages.NaryAttributeEditingDialog_delete);
323
		final GridData removeButtonGridData = new GridData();
324
		removeButtonGridData.verticalAlignment = SWT.FILL;
325
		removeButtonGridData.horizontalAlignment = SWT.FILL;
326
		this.fRemoveButton.setLayoutData(removeButtonGridData);
327
328
		spacer(buttonsComposite);
329
330
		this.fUpButton = new Button(buttonsComposite, SWT.PUSH);
331
		this.fUpButton.setText(Messages.NaryReferenceEditingDialog_up);
332
		final GridData upButtonGridData = new GridData();
333
		upButtonGridData.verticalAlignment = SWT.FILL;
334
		upButtonGridData.horizontalAlignment = SWT.FILL;
335
		this.fUpButton.setLayoutData(upButtonGridData);
336
337
		this.fDownButton = new Button(buttonsComposite, SWT.PUSH);
338
		this.fDownButton.setText(Messages.NaryReferenceEditingDialog_down);
339
		final GridData downButtonGridData = new GridData();
340
		downButtonGridData.verticalAlignment = SWT.FILL;
341
		downButtonGridData.horizontalAlignment = SWT.FILL;
342
		this.fDownButton.setLayoutData(downButtonGridData);
343
	}
344
345
	private void createValuesPane(final Composite contents) {
346
		final Composite featureComposite = new Composite(contents, SWT.NONE);
347
		final GridData featureCompositeData = new GridData(SWT.FILL, SWT.FILL, true, true);
348
		featureCompositeData.horizontalAlignment = SWT.END;
349
		featureComposite.setLayoutData(featureCompositeData);
350
351
		final GridLayout featureCompositeLayout = new GridLayout();
352
		featureCompositeData.horizontalAlignment = SWT.FILL;
353
		featureCompositeLayout.marginHeight = 0;
354
		featureCompositeLayout.marginWidth = 0;
355
		featureCompositeLayout.numColumns = 1;
356
		featureComposite.setLayout(featureCompositeLayout);
357
358
		final Label featureLabel = new Label(featureComposite, SWT.NONE);
359
		featureLabel.setText(Messages.NaryReferenceEditingDialog_values);
360
		final GridData valuesLabelGridData = new GridData();
361
		valuesLabelGridData.horizontalSpan = 2;
362
		valuesLabelGridData.horizontalAlignment = SWT.FILL;
363
		valuesLabelGridData.verticalAlignment = SWT.FILL;
364
		featureLabel.setLayoutData(valuesLabelGridData);
365
366
		final Table table = new Table(featureComposite, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION);
367
		final GridData tableGridData = new GridData();
368
		tableGridData.widthHint = NaryAttributeEditingDialog.LIST_WIDTH;
369
		tableGridData.heightHint = NaryAttributeEditingDialog.LIST_HEIGHT;
370
		tableGridData.verticalAlignment = SWT.FILL;
371
		tableGridData.horizontalAlignment = SWT.FILL;
372
		tableGridData.grabExcessHorizontalSpace = true;
373
		tableGridData.grabExcessVerticalSpace = true;
374
		table.setLayoutData(tableGridData);
375
		final TableColumn tableColumn = new TableColumn(table, SWT.CENTER);
376
377
		// full-width column
378
		table.addControlListener(new ControlListener() {
379
			public void controlResized(final ControlEvent e) {
380
				tableColumn.setWidth(table.getClientArea().width);
381
			}
382
383
			public void controlMoved(final ControlEvent e) {
384
				//
385
			}
386
		});
387
388
		this.fFeatureValuesTableViewer = new TableViewer(table);
389
		this.fFeatureValuesTableViewer.setContentProvider(new AssignedValuesContentProvider());
390
		// this.fFeatureValuesTableViewer.setLabelProvider(this.labelProvider);
391
		this.fFeatureValuesTableViewer
392
				.setInput(new FeatureValuesInput(this.fFeature, this.fEObject));
393
394
		final TableViewerColumn tableViewerColumn = new TableViewerColumn(
395
				this.fFeatureValuesTableViewer, tableColumn);
396
		tableViewerColumn.setLabelProvider(this.labelProvider);
397
398
		tableViewerColumn.setEditingSupport(new ModelCellsEditingSupport(
399
				this.fFeatureValuesTableViewer, this.fFeature, this.fEObject, this.editingDomain,
400
				this.newValuePlaceholder));
401
402
		// keyboard accessibility
403
		table.addKeyListener(new KeyAdapter() {
404
			@Override
405
			public void keyPressed(final KeyEvent e) {
406
				if (e.keyCode == SWT.F2) {
407
					editSelectedElement();
408
				}
409
				if (e.keyCode == SWT.DEL) {
410
					if (NaryAttributeEditingDialog.this.fRemoveButton.isEnabled()) {
411
						NaryAttributeEditingDialog.this.fRemoveButton.notifyListeners(
412
								SWT.Selection, null);
413
					}
414
				}
415
				if (e.keyCode == SWT.ARROW_UP
416
						&& ((e.stateMask & SWT.COMMAND) != 0 || (e.stateMask & SWT.CONTROL) != 0)) {
417
					if (NaryAttributeEditingDialog.this.fUpButton.isEnabled()) {
418
						NaryAttributeEditingDialog.this.fUpButton.notifyListeners(SWT.Selection,
419
								null);
420
					}
421
				}
422
				if (e.keyCode == SWT.ARROW_DOWN
423
						&& ((e.stateMask & SWT.COMMAND) != 0 || (e.stateMask & SWT.CONTROL) != 0)) {
424
					if (NaryAttributeEditingDialog.this.fDownButton.isEnabled()) {
425
						NaryAttributeEditingDialog.this.fDownButton.notifyListeners(SWT.Selection,
426
								null);
427
					}
428
				}
429
			}
430
		});
431
432
	}
433
434
	private void editSelectedElement() {
435
		ISelection selection = NaryAttributeEditingDialog.this.fFeatureValuesTableViewer
436
				.getSelection();
437
		if (selection instanceof IStructuredSelection) {
438
			IStructuredSelection structuredSelection = (IStructuredSelection) selection;
439
			if (structuredSelection.getFirstElement() != null) {
440
				NaryAttributeEditingDialog.this.fFeatureValuesTableViewer.editElement(
441
						structuredSelection.getFirstElement(), 0);
442
			}
443
		}
444
	}
445
446
	@Override
447
	protected void okPressed() {
448
		super.okPressed();
449
	}
450
451
	private void refresh() {
452
		this.fFeatureValuesTableViewer.refresh();
453
	}
454
455
	@Override
456
	protected boolean isResizable() {
457
		return true;
458
	}
459
460
	@Override
461
	protected void createButtonsForButtonBar(final Composite parent) {
462
		createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
463
	}
464
}
(-)src/org/eclipse/emf/facet/widgets/nattable/workbench/editor/NatTableEditorFactory.java (-2 / +4 lines)
Lines 106-114 Link Here
106
		} else {
106
		} else {
107
			int nElements = tableElements.size();
107
			int nElements = tableElements.size();
108
			if (nElements > 1) {
108
			if (nElements > 1) {
109
				description = NLS.bind(Messages.NatTableEditorFactory_queryResults, new Integer(nElements));
109
				description = NLS.bind(Messages.NatTableEditorFactory_queryResults, new Integer(
110
						nElements));
110
			} else {
111
			} else {
111
				description = NLS.bind(Messages.NatTableEditorFactory_queryResult, new Integer(nElements));
112
				description = NLS.bind(Messages.NatTableEditorFactory_queryResult, new Integer(
113
						nElements));
112
			}
114
			}
113
			queryName = Messages.NatTableEditorFactory_aQuery;
115
			queryName = Messages.NatTableEditorFactory_aQuery;
114
		}
116
		}
(-)src/org/eclipse/emf/facet/widgets/nattable/workbench/view/NatTableView.java (-3 / +5 lines)
Lines 73-79 Link Here
73
		List<TableElement> tableElements = new ArrayList<TableElement>();
73
		List<TableElement> tableElements = new ArrayList<TableElement>();
74
		for (ModelQueryResult modelQueryResult : result) {
74
		for (ModelQueryResult modelQueryResult : result) {
75
			Object value = modelQueryResult.getValue();
75
			Object value = modelQueryResult.getValue();
76
			TableElementWithContext.flattenToList(value, tableElements, modelQueryResult.getSource());
76
			TableElementWithContext.flattenToList(value, tableElements,
77
					modelQueryResult.getSource());
77
		}
78
		}
78
		openOn(new TableInput(tableElements, editingDomain));
79
		openOn(new TableInput(tableElements, editingDomain));
79
	}
80
	}
Lines 150-156 Link Here
150
		manager.add(this.actionSortColumnsByType);
151
		manager.add(this.actionSortColumnsByType);
151
		manager.add(this.actionHideEmptyColumns);
152
		manager.add(this.actionHideEmptyColumns);
152
		manager.add(this.actionOnlyShowCommonColumns);
153
		manager.add(this.actionOnlyShowCommonColumns);
153
		
154
154
	}
155
	}
155
156
156
	private void fillContextMenu(final IMenuManager manager) {
157
	private void fillContextMenu(final IMenuManager manager) {
Lines 220-226 Link Here
220
			}
221
			}
221
		};
222
		};
222
223
223
		this.actionRemoveLine = new Action(Messages.NatTableView_removeSelectedLines, IAction.AS_PUSH_BUTTON) {
224
		this.actionRemoveLine = new Action(Messages.NatTableView_removeSelectedLines,
225
				IAction.AS_PUSH_BUTTON) {
224
			{
226
			{
225
				setToolTipText(Messages.NatTableView_removeSelectedLines);
227
				setToolTipText(Messages.NatTableView_removeSelectedLines);
226
				setImageDescriptor(ImageProvider.getInstance().getRemoveLineIconDescriptor());
228
				setImageDescriptor(ImageProvider.getInstance().getRemoveLineIconDescriptor());

Return to bug 331633