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 337930 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jpt/common/ui/internal/widgets/Pane.java (-137 / +161 lines)
Lines 149-162 Link Here
149
	 * {@link #enableWidgets(boolean)} is called.
149
	 * {@link #enableWidgets(boolean)} is called.
150
	 */
150
	 */
151
	private ArrayList<Control> managedWidgets;
151
	private ArrayList<Control> managedWidgets;
152
	
152
153
	/**
153
	/**
154
	 * The collection of <code>Pane</code>s that are displayed in this pane,
154
	 * The collection of <code>Pane</code>s that are displayed in this pane,
155
	 * which will have their enablement state updated when
155
	 * which will have their enablement state updated when
156
	 * {@link #enableWidgets(boolean)} is called.
156
	 * {@link #enableWidgets(boolean)} is called.
157
	 */
157
	 */
158
	private ArrayList<Pane<?>> managedSubPanes;
158
	private ArrayList<Pane<?>> managedSubPanes;
159
	
159
160
	/**
160
	/**
161
	 * This enabled model is used to store the pane's base enablement state.
161
	 * This enabled model is used to store the pane's base enablement state.
162
	 * If API is called to set the pane enabled, this model gets updated.  If the pane is thereby
162
	 * If API is called to set the pane enabled, this model gets updated.  If the pane is thereby
Lines 164-188 Link Here
164
	 * enabled.
164
	 * enabled.
165
	 * @see #getCombinedEnabledModel()
165
	 * @see #getCombinedEnabledModel()
166
	 */
166
	 */
167
	private final WritablePropertyValueModel<Boolean> baseEnabledModel 
167
	private final WritablePropertyValueModel<Boolean> baseEnabledModel
168
			= new SimplePropertyValueModel<Boolean>(Boolean.TRUE);
168
			= new SimplePropertyValueModel<Boolean>(Boolean.TRUE);
169
	
169
170
	/**
170
	/**
171
	 * This enabled model is used to define the pane's enablement as controlled by other widgets,
171
	 * This enabled model is used to define the pane's enablement as controlled by other widgets,
172
	 * tests, etc. (for example a radio button)
172
	 * tests, etc. (for example a radio button)
173
	 * If this model is changed, and the pane is thereby fully enabled (base enabled model is also 
173
	 * If this model is changed, and the pane is thereby fully enabled (base enabled model is also
174
	 * in agreement) the pane's widgets are set enabled.
174
	 * in agreement) the pane's widgets are set enabled.
175
	 * @see #getCombinedEnabledModel()
175
	 * @see #getCombinedEnabledModel()
176
	 */
176
	 */
177
	private PropertyValueModel<Boolean> controllerEnabledModel;
177
	private PropertyValueModel<Boolean> controllerEnabledModel;
178
	
178
179
	/**
179
	/**
180
	 * The "and" combination of {@link #baseEnabledModel} and {@link #controllerEnabledModel}
180
	 * The "and" combination of {@link #baseEnabledModel} and {@link #controllerEnabledModel}
181
	 */
181
	 */
182
	private PropertyValueModel<Boolean> combinedEnabledModel;
182
	private PropertyValueModel<Boolean> combinedEnabledModel;
183
	
183
184
	private PropertyChangeListener combinedEnabledModelListener;
184
	private PropertyChangeListener combinedEnabledModelListener;
185
	
185
186
	/**
186
	/**
187
	 * Creates a new <code>Pane</code>.
187
	 * Creates a new <code>Pane</code>.
188
	 *
188
	 *
Lines 194-200 Link Here
194
	protected Pane(
194
	protected Pane(
195
			Pane<? extends T> parentPane,
195
			Pane<? extends T> parentPane,
196
	        Composite parent) {
196
	        Composite parent) {
197
		
197
198
		this(parentPane, parent, true);
198
		this(parentPane, parent, true);
199
	}
199
	}
200
200
Lines 214-220 Link Here
214
			Pane<? extends T> parentPane,
214
			Pane<? extends T> parentPane,
215
	        Composite parent,
215
	        Composite parent,
216
	        boolean automaticallyAlignWidgets) {
216
	        boolean automaticallyAlignWidgets) {
217
		
217
218
		this(
218
		this(
219
			parentPane,
219
			parentPane,
220
			parentPane.getSubjectHolder(),
220
			parentPane.getSubjectHolder(),
Lines 239-245 Link Here
239
	        Composite parent,
239
	        Composite parent,
240
	        boolean automaticallyAlignWidgets,
240
	        boolean automaticallyAlignWidgets,
241
	        boolean parentManagePane) {
241
	        boolean parentManagePane) {
242
		
242
243
		this(
243
		this(
244
			parentPane,
244
			parentPane,
245
			parentPane.getSubjectHolder(),
245
			parentPane.getSubjectHolder(),
Lines 261-276 Link Here
261
			Pane<?> parentPane,
261
			Pane<?> parentPane,
262
	        PropertyValueModel<? extends T> subjectHolder,
262
	        PropertyValueModel<? extends T> subjectHolder,
263
	        Composite parent) {
263
	        Composite parent) {
264
		
264
265
		this(parentPane, subjectHolder, parent, true);
265
		this(parentPane, subjectHolder, parent, true);
266
	}
266
	}
267
	
267
268
	protected Pane(
268
	protected Pane(
269
			Pane<?> parentPane,
269
			Pane<?> parentPane,
270
	        PropertyValueModel<? extends T> subjectHolder,
270
	        PropertyValueModel<? extends T> subjectHolder,
271
	        Composite parent,
271
	        Composite parent,
272
	        PropertyValueModel<Boolean> enabledModel) {
272
	        PropertyValueModel<Boolean> enabledModel) {
273
		
273
274
		this(parentPane, subjectHolder, parent, true, enabledModel);
274
		this(parentPane, subjectHolder, parent, true, enabledModel);
275
	}
275
	}
276
276
Lines 292-311 Link Here
292
			PropertyValueModel<? extends T> subjectHolder,
292
			PropertyValueModel<? extends T> subjectHolder,
293
			Composite parent,
293
			Composite parent,
294
			boolean automaticallyAlignWidgets) {
294
			boolean automaticallyAlignWidgets) {
295
		
295
296
		this(parentPane, subjectHolder, parent, automaticallyAlignWidgets, true);
296
		this(parentPane, subjectHolder, parent, automaticallyAlignWidgets, true);
297
	}
297
	}
298
	
298
299
	protected Pane(
299
	protected Pane(
300
			Pane<?> parentPane,
300
			Pane<?> parentPane,
301
			PropertyValueModel<? extends T> subjectHolder,
301
			PropertyValueModel<? extends T> subjectHolder,
302
			Composite parent,
302
			Composite parent,
303
			boolean automaticallyAlignWidgets,
303
			boolean automaticallyAlignWidgets,
304
			PropertyValueModel<Boolean> enabledModel) {
304
			PropertyValueModel<Boolean> enabledModel) {
305
		
305
306
		this(parentPane, subjectHolder, parent, automaticallyAlignWidgets, true, enabledModel);
306
		this(parentPane, subjectHolder, parent, automaticallyAlignWidgets, true, enabledModel);
307
	}
307
	}
308
	
308
309
	/**
309
	/**
310
	 * Creates a new <code>Pane</code>.
310
	 * Creates a new <code>Pane</code>.
311
	 *
311
	 *
Lines 325-350 Link Here
325
			Pane<?> parentPane,
325
			Pane<?> parentPane,
326
			PropertyValueModel<? extends T> subjectHolder,
326
			PropertyValueModel<? extends T> subjectHolder,
327
			Composite parent,
327
			Composite parent,
328
			boolean automaticallyAlignWidgets, 
328
			boolean automaticallyAlignWidgets,
329
			boolean parentManagePane) {
329
			boolean parentManagePane) {
330
		
330
331
		this(subjectHolder, parent, parentPane.getWidgetFactory());
331
		this(subjectHolder, parent, parentPane.getWidgetFactory());
332
		this.initialize(parentPane, automaticallyAlignWidgets, parentManagePane);
332
		this.initialize(parentPane, automaticallyAlignWidgets, parentManagePane);
333
	}
333
	}
334
	
334
335
	protected Pane(
335
	protected Pane(
336
			Pane<?> parentPane,
336
			Pane<?> parentPane,
337
			PropertyValueModel<? extends T> subjectHolder,
337
			PropertyValueModel<? extends T> subjectHolder,
338
			Composite parent,
338
			Composite parent,
339
			boolean automaticallyAlignWidgets, 
339
			boolean automaticallyAlignWidgets,
340
			boolean parentManagePane,
340
			boolean parentManagePane,
341
			PropertyValueModel<Boolean> enabledModel) {
341
			PropertyValueModel<Boolean> enabledModel) {
342
		
342
343
		this(subjectHolder, parent, parentPane.getWidgetFactory());
343
		this(subjectHolder, parent, parentPane.getWidgetFactory());
344
		this.initialize(parentPane, automaticallyAlignWidgets, parentManagePane);
344
		this.initialize(parentPane, automaticallyAlignWidgets, parentManagePane);
345
		this.initializeEnabledModel(enabledModel);
345
		this.initializeEnabledModel(enabledModel);
346
	}
346
	}
347
	
347
348
	/**
348
	/**
349
	 * Creates a new <code>Pane</code>.
349
	 * Creates a new <code>Pane</code>.
350
	 *
350
	 *
Lines 358-364 Link Here
358
			PropertyValueModel<? extends T> subjectHolder,
358
			PropertyValueModel<? extends T> subjectHolder,
359
			Composite parent,
359
			Composite parent,
360
			WidgetFactory widgetFactory) {
360
			WidgetFactory widgetFactory) {
361
		
361
362
		super();
362
		super();
363
		this.initialize(subjectHolder, widgetFactory);
363
		this.initialize(subjectHolder, widgetFactory);
364
		this.container = this.addContainer(parent);
364
		this.container = this.addContainer(parent);
Lines 375-381 Link Here
375
	private void initialize(
375
	private void initialize(
376
			PropertyValueModel<? extends T> subjectHolder,
376
			PropertyValueModel<? extends T> subjectHolder,
377
	        WidgetFactory widgetFactory) {
377
	        WidgetFactory widgetFactory) {
378
		
378
379
		Assert.isNotNull(subjectHolder, "The subject holder cannot be null");
379
		Assert.isNotNull(subjectHolder, "The subject holder cannot be null");
380
380
381
		this.subjectHolder         = (PropertyValueModel<T>) subjectHolder;
381
		this.subjectHolder         = (PropertyValueModel<T>) subjectHolder;
Lines 387-393 Link Here
387
		this.rightControlAligner   = new ControlAligner();
387
		this.rightControlAligner   = new ControlAligner();
388
		this.subjectChangeListener = this.buildSubjectChangeListener();
388
		this.subjectChangeListener = this.buildSubjectChangeListener();
389
		this.aspectChangeListener  = this.buildAspectChangeListener();
389
		this.aspectChangeListener  = this.buildAspectChangeListener();
390
		
390
391
		this.initialize();
391
		this.initialize();
392
	}
392
	}
393
393
Lines 411-426 Link Here
411
			Pane<?> parentPane,
411
			Pane<?> parentPane,
412
			boolean automaticallyAlignWidgets,
412
			boolean automaticallyAlignWidgets,
413
	        boolean parentManagePane) {
413
	        boolean parentManagePane) {
414
		
414
415
		// Register this pane with the parent pane, it will call the methods
415
		// Register this pane with the parent pane, it will call the methods
416
		// automatically (engageListeners(), disengageListeners(), populate(),
416
		// automatically (engageListeners(), disengageListeners(), populate(),
417
		// dispose(), etc)
417
		// dispose(), etc)
418
		parentPane.registerSubPane(this);
418
		parentPane.registerSubPane(this);
419
		
419
420
		if (parentManagePane) {
420
		if (parentManagePane) {
421
			parentPane.manageSubPane(this);
421
			parentPane.manageSubPane(this);
422
		}
422
		}
423
		
423
424
		// Align the left and right controls with the controls from the parent
424
		// Align the left and right controls with the controls from the parent
425
		// pane
425
		// pane
426
		if (automaticallyAlignWidgets) {
426
		if (automaticallyAlignWidgets) {
Lines 428-448 Link Here
428
			parentPane.addAlignRight(this);
428
			parentPane.addAlignRight(this);
429
		}
429
		}
430
	}
430
	}
431
	
431
432
	private void initializeEnabledModel(PropertyValueModel<Boolean> enabledModel) {
432
	private void initializeEnabledModel(PropertyValueModel<Boolean> enabledModel) {
433
		this.controllerEnabledModel = enabledModel;
433
		this.controllerEnabledModel = enabledModel;
434
		this.combinedEnabledModel = 
434
		this.combinedEnabledModel =
435
				CompositeBooleanPropertyValueModel.and(this.baseEnabledModel, this.controllerEnabledModel);
435
				CompositeBooleanPropertyValueModel.and(this.baseEnabledModel, this.controllerEnabledModel);
436
		this.combinedEnabledModelListener = buildCombinedEnabledModelListener();
436
		this.combinedEnabledModelListener = buildCombinedEnabledModelListener();
437
		this.combinedEnabledModel.addPropertyChangeListener(
437
		this.combinedEnabledModel.addPropertyChangeListener(
438
				PropertyValueModel.VALUE, this.combinedEnabledModelListener);
438
				PropertyValueModel.VALUE, this.combinedEnabledModelListener);
439
		enableWidgets_(getCombinedEnablement());
439
		enableWidgets_(getCombinedEnablement());
440
	}
440
	}
441
	
441
442
	private PropertyChangeListener buildCombinedEnabledModelListener() {
442
	private PropertyChangeListener buildCombinedEnabledModelListener() {
443
		return new SWTPropertyChangeListenerWrapper(buildControllerEnabledModelListener_());
443
		return new SWTPropertyChangeListenerWrapper(buildControllerEnabledModelListener_());
444
	}
444
	}
445
	
445
446
	private PropertyChangeListener buildControllerEnabledModelListener_() {
446
	private PropertyChangeListener buildControllerEnabledModelListener_() {
447
		return new PropertyChangeListener() {
447
		return new PropertyChangeListener() {
448
			@SuppressWarnings("unchecked")
448
			@SuppressWarnings("unchecked")
Lines 451-457 Link Here
451
			}
451
			}
452
		};
452
		};
453
	}
453
	}
454
	
454
455
	/**
455
	/**
456
	 * Initializes the layout of this pane.
456
	 * Initializes the layout of this pane.
457
	 *
457
	 *
Lines 467-473 Link Here
467
		}
467
		}
468
		this.managedWidgets.add(control);
468
		this.managedWidgets.add(control);
469
	}
469
	}
470
	
470
471
	private void manageSubPane(Pane<?> subPane) {
471
	private void manageSubPane(Pane<?> subPane) {
472
		if (this.managedSubPanes.contains(subPane)) {
472
		if (this.managedSubPanes.contains(subPane)) {
473
			throw new IllegalStateException();
473
			throw new IllegalStateException();
Lines 585-594 Link Here
585
585
586
		return this.addButton(container, text, null, buttonAction);
586
		return this.addButton(container, text, null, buttonAction);
587
	}
587
	}
588
	
588
589
	/**
589
	/**
590
	 * Creates a new unmanaged <code>Button</code> widget.  Unmanaged means 
590
	 * Creates a new unmanaged <code>Button</code> widget.  Unmanaged means
591
	 * that this Pane will not handle the enabling/disabling of this widget.  
591
	 * that this Pane will not handle the enabling/disabling of this widget.
592
	 * The owning object will handle it with its own PaneEnabler or ControlEnabler.
592
	 * The owning object will handle it with its own PaneEnabler or ControlEnabler.
593
	 *
593
	 *
594
	 * @param parent The parent container
594
	 * @param parent The parent container
Lines 626-635 Link Here
626
626
627
		return button;
627
		return button;
628
	}
628
	}
629
	
629
630
	/**
630
	/**
631
	 * Creates a new unmanaged <code>Button</code> widget.  Unmanaged means 
631
	 * Creates a new unmanaged <code>Button</code> widget.  Unmanaged means
632
	 * that this Pane will not handle the enabling/disabling of this widget.  
632
	 * that this Pane will not handle the enabling/disabling of this widget.
633
	 * The owning object will handle it with its own PaneEnabler or ControlEnabler.
633
	 * The owning object will handle it with its own PaneEnabler or ControlEnabler.
634
	 *
634
	 *
635
	 * @param parent The parent container
635
	 * @param parent The parent container
Lines 697-703 Link Here
697
	        String buttonText,
697
	        String buttonText,
698
	        WritablePropertyValueModel<Boolean> booleanHolder,
698
	        WritablePropertyValueModel<Boolean> booleanHolder,
699
	        String helpId) {
699
	        String helpId) {
700
		
700
701
		return this.addToggleButton(
701
		return this.addToggleButton(
702
			parent,
702
			parent,
703
			buttonText,
703
			buttonText,
Lines 705-723 Link Here
705
			helpId,
705
			helpId,
706
			SWT.CHECK);
706
			SWT.CHECK);
707
	}
707
	}
708
	
708
709
	protected final Button addCheckBox(
709
	protected final Button addCheckBox(
710
			Composite parent,
710
			Composite parent,
711
			String buttonText,
711
			String buttonText,
712
			WritablePropertyValueModel<Boolean> booleanHolder,
712
			WritablePropertyValueModel<Boolean> booleanHolder,
713
			String helpId,
713
			String helpId,
714
			PropertyValueModel<Boolean> enabledModel) {
714
			PropertyValueModel<Boolean> enabledModel) {
715
		
715
716
		Button button = this.addUnmanagedToggleButton(parent, buttonText, booleanHolder, helpId, SWT.CHECK);
716
		Button button = this.addUnmanagedToggleButton(parent, buttonText, booleanHolder, helpId, SWT.CHECK);
717
		this.controlEnabledState(enabledModel, button);
717
		this.controlEnabledState(enabledModel, button);
718
		return button;
718
		return button;
719
	}
719
	}
720
	
720
721
	/**
721
	/**
722
	 * Creates a new <code>Section</code> that can be collapsed. A sub-pane is
722
	 * Creates a new <code>Section</code> that can be collapsed. A sub-pane is
723
	 * automatically added as its client and is the returned <code>Composite</code>.
723
	 * automatically added as its client and is the returned <code>Composite</code>.
Lines 731-743 Link Here
731
	protected final Composite addCollapsibleSection(
731
	protected final Composite addCollapsibleSection(
732
			Composite container,
732
			Composite container,
733
	        String sectionText) {
733
	        String sectionText) {
734
		
734
735
		return this.addCollapsibleSection(
735
		return this.addCollapsibleSection(
736
				container,
736
				container,
737
				sectionText,
737
				sectionText,
738
				new SimplePropertyValueModel<Boolean>(Boolean.FALSE));
738
				new SimplePropertyValueModel<Boolean>(Boolean.FALSE));
739
	}
739
	}
740
	
740
741
	/**
741
	/**
742
	 * Creates a new <code>Section</code> that can be collapsed. A sub-pane is
742
	 * Creates a new <code>Section</code> that can be collapsed. A sub-pane is
743
	 * automatically added as its client and is the returned <code>Composite</code>.
743
	 * automatically added as its client and is the returned <code>Composite</code>.
Lines 778-787 Link Here
778
	                                          String sectionText,
778
	                                          String sectionText,
779
	                                          int type,
779
	                                          int type,
780
	                                          PropertyValueModel<Boolean> expandedStateHolder) {
780
	                                          PropertyValueModel<Boolean> expandedStateHolder) {
781
		
781
782
		return addCollapsibleSection(container, sectionText, null, type, expandedStateHolder);
782
		return addCollapsibleSection(container, sectionText, null, type, expandedStateHolder);
783
	}
783
	}
784
	
784
785
	/**
785
	/**
786
	 * Creates a new <code>Section</code>. A sub-pane is automatically added as
786
	 * Creates a new <code>Section</code>. A sub-pane is automatically added as
787
	 * its client and is the returned <code>Composite</code>.
787
	 * its client and is the returned <code>Composite</code>.
Lines 847-853 Link Here
847
			expandedStateHolder
847
			expandedStateHolder
848
		);
848
		);
849
	}
849
	}
850
	
850
851
	/**
851
	/**
852
	 * Creates a new <code>Section</code>. A sub-pane is automatically added as
852
	 * Creates a new <code>Section</code>. A sub-pane is automatically added as
853
	 * its client and is the returned <code>Composite</code>.
853
	 * its client and is the returned <code>Composite</code>.
Lines 991-997 Link Here
991
			WritablePropertyValueModel<V> selectedItemHolder,
991
			WritablePropertyValueModel<V> selectedItemHolder,
992
			StringConverter<V> stringConverter,
992
			StringConverter<V> stringConverter,
993
			PropertyValueModel<Boolean> enabledModel) {
993
			PropertyValueModel<Boolean> enabledModel) {
994
		
994
995
		Combo combo = this.addUnmanagedCombo(container, listHolder, selectedItemHolder, stringConverter);
995
		Combo combo = this.addUnmanagedCombo(container, listHolder, selectedItemHolder, stringConverter);
996
		this.controlEnabledState(enabledModel, combo);
996
		this.controlEnabledState(enabledModel, combo);
997
		return combo;
997
		return combo;
Lines 1029-1056 Link Here
1029
	protected Composite addContainer(Composite parent) {
1029
	protected Composite addContainer(Composite parent) {
1030
		return this.addSubPane(parent);
1030
		return this.addSubPane(parent);
1031
	}
1031
	}
1032
	
1032
1033
	protected final <V> Combo addEditableCombo(
1033
	protected final <V> Combo addEditableCombo(
1034
			Composite container,
1034
			Composite container,
1035
			ListValueModel<V> listHolder,
1035
			ListValueModel<V> listHolder,
1036
			WritablePropertyValueModel<V> selectedItemHolder,
1036
			WritablePropertyValueModel<V> selectedItemHolder,
1037
			StringConverter<V> stringConverter,
1037
			StringConverter<V> stringConverter,
1038
			PropertyValueModel<Boolean> enabledModel) {
1038
			PropertyValueModel<Boolean> enabledModel) {
1039
		
1039
1040
		Combo combo = this.addUnmanagedEditableCombo(container, listHolder, selectedItemHolder, stringConverter);
1040
		Combo combo = this.addUnmanagedEditableCombo(container, listHolder, selectedItemHolder, stringConverter);
1041
		this.controlEnabledState(enabledModel, combo);
1041
		this.controlEnabledState(enabledModel, combo);
1042
		return combo;
1042
		return combo;
1043
	}
1043
	}
1044
	
1044
1045
	protected final Combo addEditableCombo(
1045
	protected final Combo addEditableCombo(
1046
			Composite container) {
1046
			Composite container) {
1047
		
1047
1048
		Combo combo = this.widgetFactory.createEditableCombo(container);
1048
		Combo combo = this.widgetFactory.createEditableCombo(container);
1049
		combo.setLayoutData(getFieldGridData());
1049
		combo.setLayoutData(getFieldGridData());
1050
		this.manageWidget(combo);
1050
		this.manageWidget(combo);
1051
		return combo;
1051
		return combo;
1052
	}
1052
	}
1053
	
1053
1054
	/**
1054
	/**
1055
	 * Creates a new editable <code>Combo</code>.
1055
	 * Creates a new editable <code>Combo</code>.
1056
	 *
1056
	 *
Lines 1159-1165 Link Here
1159
	 */
1159
	 */
1160
	protected final Label addLabel(Composite container,
1160
	protected final Label addLabel(Composite container,
1161
	                                 String labelText) {
1161
	                                 String labelText) {
1162
		
1162
1163
		Label label = addUnmanagedLabel(container, labelText);
1163
		Label label = addUnmanagedLabel(container, labelText);
1164
		manageWidget(label);
1164
		manageWidget(label);
1165
		return label;
1165
		return label;
Lines 1176-1183 Link Here
1176
	}
1176
	}
1177
1177
1178
	/**
1178
	/**
1179
	 * Creates a new unmanaged <code>Label</code> widget.  Unmanaged means 
1179
	 * Creates a new unmanaged <code>Label</code> widget.  Unmanaged means
1180
	 * that this Pane will not handle the enabling/disabling of this widget.  
1180
	 * that this Pane will not handle the enabling/disabling of this widget.
1181
	 * The owning object will handle it with its own PaneEnabler or ControlEnabler.
1181
	 * The owning object will handle it with its own PaneEnabler or ControlEnabler.
1182
	 *
1182
	 *
1183
	 * @param parent The parent container
1183
	 * @param parent The parent container
Lines 1201-1207 Link Here
1201
	 * @param selectedItemHolder The holder of the selected item
1201
	 * @param selectedItemHolder The holder of the selected item
1202
	 * @param rightControl The control shown to the right of the main widget
1202
	 * @param rightControl The control shown to the right of the main widget
1203
	 * @param helpId The topic help ID to be registered for the given center
1203
	 * @param helpId The topic help ID to be registered for the given center
1204
	 * compositer
1204
	 * composite
1205
	 * @return The container of the label and the given center control
1205
	 * @return The container of the label and the given center control
1206
	 *
1206
	 *
1207
	 * @category Layout
1207
	 * @category Layout
Lines 1241-1247 Link Here
1241
	 * @param listHolder The <code>ListValueHolder</code>
1241
	 * @param listHolder The <code>ListValueHolder</code>
1242
	 * @param selectedItemHolder The holder of the selected item
1242
	 * @param selectedItemHolder The holder of the selected item
1243
	 * @param helpId The topic help ID to be registered for the given center
1243
	 * @param helpId The topic help ID to be registered for the given center
1244
	 * compositer
1244
	 * composite
1245
	 * @return The container of the label and the given center control
1245
	 * @return The container of the label and the given center control
1246
	 *
1246
	 *
1247
	 * @category Layout
1247
	 * @category Layout
Lines 1273-1279 Link Here
1273
	 * @param centerControl The main widget
1273
	 * @param centerControl The main widget
1274
	 * @param rightControl The control shown to the right of the main widget
1274
	 * @param rightControl The control shown to the right of the main widget
1275
	 * @param helpId The topic help ID to be registered for the given center
1275
	 * @param helpId The topic help ID to be registered for the given center
1276
	 * compositer
1276
	 * composite
1277
	 * @return The container of the label and the given center control
1277
	 * @return The container of the label and the given center control
1278
	 *
1278
	 *
1279
	 * @category Layout
1279
	 * @category Layout
Lines 1330-1336 Link Here
1330
1330
1331
		return container;
1331
		return container;
1332
	}
1332
	}
1333
	
1333
1334
	/**
1334
	/**
1335
	 * Creates a new container that will have the given center control labeled
1335
	 * Creates a new container that will have the given center control labeled
1336
	 * with the given label.
1336
	 * with the given label.
Lines 1366-1372 Link Here
1366
	 * @param labelText The text to label the main composite
1366
	 * @param labelText The text to label the main composite
1367
	 * @param centerPane The main widget
1367
	 * @param centerPane The main widget
1368
	 * @param helpId The topic help ID to be registered for the given center
1368
	 * @param helpId The topic help ID to be registered for the given center
1369
	 * compositer
1369
	 * composite
1370
	 * @return The container of the label and the given center control
1370
	 * @return The container of the label and the given center control
1371
	 *
1371
	 *
1372
	 * @category Layout
1372
	 * @category Layout
Lines 1418-1424 Link Here
1418
	 * @param centerControl The main widget
1418
	 * @param centerControl The main widget
1419
	 * @param rightControl The control shown to the right of the main widget
1419
	 * @param rightControl The control shown to the right of the main widget
1420
	 * @param helpId The topic help ID to be registered for the given center
1420
	 * @param helpId The topic help ID to be registered for the given center
1421
	 * compositer
1421
	 * composite
1422
	 * @return The container of the label and the given center control
1422
	 * @return The container of the label and the given center control
1423
	 *
1423
	 *
1424
	 * @category Layout
1424
	 * @category Layout
Lines 1446-1452 Link Here
1446
	 * @param labelText The text to label the main composite
1446
	 * @param labelText The text to label the main composite
1447
	 * @param centerControl The main widget
1447
	 * @param centerControl The main widget
1448
	 * @param helpId The topic help ID to be registered for the given center
1448
	 * @param helpId The topic help ID to be registered for the given center
1449
	 * compositer
1449
	 * composite
1450
	 * @return The container of the label and the given center control
1450
	 * @return The container of the label and the given center control
1451
	 *
1451
	 *
1452
	 * @category Layout
1452
	 * @category Layout
Lines 1475-1481 Link Here
1475
	 * @param centerControl The main widget
1475
	 * @param centerControl The main widget
1476
	 * @param rightControl The control shown to the right of the main widget
1476
	 * @param rightControl The control shown to the right of the main widget
1477
	 * @param helpId The topic help ID to be registered for the given center
1477
	 * @param helpId The topic help ID to be registered for the given center
1478
	 * compositer
1478
	 * composite
1479
	 * @return The newly created <code>CCombo</code>
1479
	 * @return The newly created <code>CCombo</code>
1480
	 *
1480
	 *
1481
	 * @category Layout
1481
	 * @category Layout
Lines 1509-1515 Link Here
1509
	 * @param comboListener The listener that will be notified when the selection
1509
	 * @param comboListener The listener that will be notified when the selection
1510
	 * changes
1510
	 * changes
1511
	 * @param helpId The topic help ID to be registered for the given center
1511
	 * @param helpId The topic help ID to be registered for the given center
1512
	 * compositer
1512
	 * composite
1513
	 * @return The newly created <code>CCombo</code>
1513
	 * @return The newly created <code>CCombo</code>
1514
	 *
1514
	 *
1515
	 * @category Layout
1515
	 * @category Layout
Lines 1539-1545 Link Here
1539
	 * into human readable strings
1539
	 * into human readable strings
1540
	 * @param rightControl The control shown to the right of the main widget
1540
	 * @param rightControl The control shown to the right of the main widget
1541
	 * @param helpId The topic help ID to be registered for the given center
1541
	 * @param helpId The topic help ID to be registered for the given center
1542
	 * compositer
1542
	 * composite
1543
	 * @return The newly created <code>CCombo</code>
1543
	 * @return The newly created <code>CCombo</code>
1544
	 *
1544
	 *
1545
	 * @category Layout
1545
	 * @category Layout
Lines 1581-1587 Link Here
1581
	 * @param labelProvider The provider responsible to convert the combo's items
1581
	 * @param labelProvider The provider responsible to convert the combo's items
1582
	 * into human readable strings
1582
	 * into human readable strings
1583
	 * @param helpId The topic help ID to be registered for the given center
1583
	 * @param helpId The topic help ID to be registered for the given center
1584
	 * compositer
1584
	 * composite
1585
	 * @return The newly created <code>CCombo</code>
1585
	 * @return The newly created <code>CCombo</code>
1586
	 *
1586
	 *
1587
	 * @category Layout
1587
	 * @category Layout
Lines 1601-1607 Link Here
1601
			helpId
1601
			helpId
1602
		);
1602
		);
1603
	}
1603
	}
1604
	
1604
1605
	/**
1605
	/**
1606
	 * Creates a new container that will have an editable combo labeled with the
1606
	 * Creates a new container that will have an editable combo labeled with the
1607
	 * given text.
1607
	 * given text.
Lines 1645-1651 Link Here
1645
	 * into a string representation
1645
	 * into a string representation
1646
	 * @param rightControl The control shown to the right of the main widget
1646
	 * @param rightControl The control shown to the right of the main widget
1647
	 * @param helpId The topic help ID to be registered for the given center
1647
	 * @param helpId The topic help ID to be registered for the given center
1648
	 * compositer
1648
	 * composite
1649
	 * @return The newly created <code>Combo</code>
1649
	 * @return The newly created <code>Combo</code>
1650
	 *
1650
	 *
1651
	 * @category Layout
1651
	 * @category Layout
Lines 1687-1693 Link Here
1687
	 * @param stringConverter The converter responsible to transform each item
1687
	 * @param stringConverter The converter responsible to transform each item
1688
	 * into a string representation
1688
	 * into a string representation
1689
	 * @param helpId The topic help ID to be registered for the given center
1689
	 * @param helpId The topic help ID to be registered for the given center
1690
	 * compositer
1690
	 * composite
1691
	 * @return The newly created <code>Combo</code>
1691
	 * @return The newly created <code>Combo</code>
1692
	 *
1692
	 *
1693
	 * @category Layout
1693
	 * @category Layout
Lines 1884-1890 Link Here
1884
1884
1885
	/**
1885
	/**
1886
	 * Creates a new managed spinner. Managed means that this Pane will
1886
	 * Creates a new managed spinner. Managed means that this Pane will
1887
	 * handle enabling/disabling of this widget if a PaneEnabler is used.  
1887
	 * handle enabling/disabling of this widget if a PaneEnabler is used.
1888
	 *
1888
	 *
1889
	 * @param parent The parent container
1889
	 * @param parent The parent container
1890
	 * @param numberHolder The holder of the integer value
1890
	 * @param numberHolder The holder of the integer value
Lines 1945-1954 Link Here
1945
1945
1946
		return spinner;
1946
		return spinner;
1947
	}
1947
	}
1948
	
1948
1949
	/**
1949
	/**
1950
	 * Creates a new managed DateTime of type SWT.TIME.  Managed means that this Pane will
1950
	 * Creates a new managed DateTime of type SWT.TIME.  Managed means that this Pane will
1951
	 * handle enabling/disabling of this widget if a PaneEnabler is used.  
1951
	 * handle enabling/disabling of this widget if a PaneEnabler is used.
1952
	 *
1952
	 *
1953
	 * @param parent The parent container
1953
	 * @param parent The parent container
1954
	 * @param hoursHolder The holder of the hours integer value
1954
	 * @param hoursHolder The holder of the hours integer value
Lines 1964-1970 Link Here
1964
											WritablePropertyValueModel<Integer> minutesHolder,
1964
											WritablePropertyValueModel<Integer> minutesHolder,
1965
											WritablePropertyValueModel<Integer> secondsHolder,
1965
											WritablePropertyValueModel<Integer> secondsHolder,
1966
											String helpId) {
1966
											String helpId) {
1967
		
1967
1968
		DateTime dateTime = this.addUnmanagedDateTime(parent, hoursHolder, minutesHolder, secondsHolder, helpId);
1968
		DateTime dateTime = this.addUnmanagedDateTime(parent, hoursHolder, minutesHolder, secondsHolder, helpId);
1969
		this.manageWidget(dateTime);
1969
		this.manageWidget(dateTime);
1970
1970
Lines 2003-2013 Link Here
2003
											WritablePropertyValueModel<Integer> minutesHolder,
2003
											WritablePropertyValueModel<Integer> minutesHolder,
2004
											WritablePropertyValueModel<Integer> secondsHolder,
2004
											WritablePropertyValueModel<Integer> secondsHolder,
2005
											String helpId) {
2005
											String helpId) {
2006
		
2006
2007
		DateTime dateTime = this.widgetFactory.createDateTime(parent, SWT.TIME);
2007
		DateTime dateTime = this.widgetFactory.createDateTime(parent, SWT.TIME);
2008
		
2008
2009
		DateTimeModelAdapter.adapt(hoursHolder, minutesHolder, secondsHolder, dateTime);
2009
		DateTimeModelAdapter.adapt(hoursHolder, minutesHolder, secondsHolder, dateTime);
2010
	
2010
2011
		if (helpId != null) {
2011
		if (helpId != null) {
2012
			getHelpSystem().setHelp(dateTime, helpId);
2012
			getHelpSystem().setHelp(dateTime, helpId);
2013
		}
2013
		}
Lines 2043-2049 Link Here
2043
		return combo;
2043
		return combo;
2044
	}
2044
	}
2045
2045
2046
	
2046
2047
	/**
2047
	/**
2048
	 * Creates a new editable <code>Combo</code>.
2048
	 * Creates a new editable <code>Combo</code>.
2049
	 *
2049
	 *
Lines 2109-2115 Link Here
2109
		return text;
2109
		return text;
2110
	}
2110
	}
2111
	/**
2111
	/**
2112
	 * 
2112
	 *
2113
	 * Creates a new container that will have a text field as the center control
2113
	 * Creates a new container that will have a text field as the center control
2114
	 * labeled with the given label.
2114
	 * labeled with the given label.
2115
	 *
2115
	 *
Lines 2233-2244 Link Here
2233
2233
2234
		return list;
2234
		return list;
2235
	}
2235
	}
2236
	
2236
2237
	/**
2237
	/**
2238
	 * Creates a new unmanaged list and notify the given selection holder when the
2238
	 * Creates a new unmanaged list and notify the given selection holder when the
2239
	 * selection changes. If the selection count is different than one than the
2239
	 * selection changes. If the selection count is different than one than the
2240
	 * holder will receive <code>null</code>. 
2240
	 * holder will receive <code>null</code>.
2241
	 * Unmanaged means that this Pane will not handle the enabling/disabling of this widget.  
2241
	 * Unmanaged means that this Pane will not handle the enabling/disabling of this widget.
2242
	 * The owning object will handle it with its own PaneEnabler or ControlEnabler.
2242
	 * The owning object will handle it with its own PaneEnabler or ControlEnabler.
2243
	 *
2243
	 *
2244
	 * @param container The parent container
2244
	 * @param container The parent container
Lines 2298-2304 Link Here
2298
2298
2299
		return text;
2299
		return text;
2300
	}
2300
	}
2301
	
2301
2302
	/**
2302
	/**
2303
	 * Creates a new <code>Text</code> widget that has multiple lines.
2303
	 * Creates a new <code>Text</code> widget that has multiple lines.
2304
	 *
2304
	 *
Lines 2310-2323 Link Here
2310
	 * @category Layout
2310
	 * @category Layout
2311
	 */
2311
	 */
2312
	protected final Text addMultiLineText(Composite container,
2312
	protected final Text addMultiLineText(Composite container,
2313
	                                        int lineCount,
2313
	                                      int lineCount,
2314
	                                        String helpId) {
2314
	                                      String helpId) {
2315
2315
2316
		Text text = this.addMultiLineText(container);
2316
		Text text = this.addMultiLineText(container);
2317
		
2317
		adjustMultiLineTextLayout(container, lineCount, text, text.getLineHeight());
2318
		GridData gridData   = getFieldGridData();
2319
		gridData.heightHint = text.getLineHeight() * lineCount;
2320
		text.setLayoutData(gridData);
2321
2318
2322
		if (helpId != null) {
2319
		if (helpId != null) {
2323
			getHelpSystem().setHelp(text, helpId);
2320
			getHelpSystem().setHelp(text, helpId);
Lines 2364-2369 Link Here
2364
	}
2361
	}
2365
2362
2366
	/**
2363
	/**
2364
	 * Adjusts the layout of the given container so that the text control has the correct amount of
2365
	 * lines by default.
2366
	 */
2367
	protected final void adjustMultiLineTextLayout(Composite container,
2368
	                                               int lineCount,
2369
	                                               Control text,
2370
	                                               int lineHeight) {
2371
2372
		int textHeight = text.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
2373
2374
		// Specify the number of lines the text area should display
2375
		GridData gridData = (GridData) text.getLayoutData();
2376
		if (gridData == null) {
2377
			gridData = this.getFieldGridData();
2378
			text.setLayoutData(gridData);
2379
		}
2380
		gridData.heightHint = lineHeight * lineCount;
2381
2382
		// Move the label to the top of its cell
2383
		Control label = container.getChildren()[0];
2384
		int labelHeight = label.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
2385
2386
		gridData = (GridData) label.getLayoutData();
2387
		gridData.verticalAlignment = SWT.TOP;
2388
		gridData.verticalIndent   += (Math.abs(textHeight - labelHeight) / 2);
2389
	}
2390
	/**
2367
	 * Creates a new <code>PageBook</code> and set the proper layout and layout
2391
	 * Creates a new <code>PageBook</code> and set the proper layout and layout
2368
	 * data.
2392
	 * data.
2369
	 *
2393
	 *
Lines 2425-2431 Link Here
2425
2449
2426
		return text;
2450
		return text;
2427
	}
2451
	}
2428
	
2452
2429
	/**
2453
	/**
2430
	 * Creates a new <code>Text</code> widget.
2454
	 * Creates a new <code>Text</code> widget.
2431
	 *
2455
	 *
Lines 2608-2614 Link Here
2608
		section.setText(sectionText);
2632
		section.setText(sectionText);
2609
		section.marginWidth  = 0;
2633
		section.marginWidth  = 0;
2610
		section.marginHeight = 0;
2634
		section.marginHeight = 0;
2611
		
2635
2612
		if (description != null) {
2636
		if (description != null) {
2613
			section.setDescription(description);
2637
			section.setDescription(description);
2614
		}
2638
		}
Lines 2869-2875 Link Here
2869
			helpId
2893
			helpId
2870
		);
2894
		);
2871
	}
2895
	}
2872
	
2896
2873
	/**
2897
	/**
2874
	 * Creates a new unmanaged table.  Unmanaged means that this Pane will
2898
	 * Creates a new unmanaged table.  Unmanaged means that this Pane will
2875
	 * not handle the enabling/disabling of this widget.  The owning object will handle
2899
	 * not handle the enabling/disabling of this widget.  The owning object will handle
Lines 2904-2913 Link Here
2904
		this.manageWidget(text);
2928
		this.manageWidget(text);
2905
		return text;
2929
		return text;
2906
	}
2930
	}
2907
	
2931
2908
	/**
2932
	/**
2909
	 * Creates a new unmanaged <code>Text</code> widget.  Unmanaged means 
2933
	 * Creates a new unmanaged <code>Text</code> widget.  Unmanaged means
2910
	 * that this Pane will not handle the enabling/disabling of this widget.  
2934
	 * that this Pane will not handle the enabling/disabling of this widget.
2911
	 * The owning object will handle it with its own PaneEnabler or ControlEnabler.
2935
	 * The owning object will handle it with its own PaneEnabler or ControlEnabler.
2912
	 *
2936
	 *
2913
	 * @param container The parent container
2937
	 * @param container The parent container
Lines 2940-2949 Link Here
2940
2964
2941
		return text;
2965
		return text;
2942
	}
2966
	}
2943
	
2967
2944
	/**
2968
	/**
2945
	 * Creates a new unmanaged <code>Text</code> widget.  Unmanaged means 
2969
	 * Creates a new unmanaged <code>Text</code> widget.  Unmanaged means
2946
	 * that this Pane will not handle the enabling/disabling of this widget.  
2970
	 * that this Pane will not handle the enabling/disabling of this widget.
2947
	 * The owning object will handle it with its own PaneEnabler or ControlEnabler.
2971
	 * The owning object will handle it with its own PaneEnabler or ControlEnabler.
2948
	 *
2972
	 *
2949
	 * @param container The parent container
2973
	 * @param container The parent container
Lines 2959-2968 Link Here
2959
		if (helpId != null) {
2983
		if (helpId != null) {
2960
			getHelpSystem().setHelp(text, helpId);
2984
			getHelpSystem().setHelp(text, helpId);
2961
		}
2985
		}
2962
		
2986
2963
		return text;
2987
		return text;
2964
	}
2988
	}
2965
	
2989
2966
	/**
2990
	/**
2967
	 * Creates a new <code>Text</code> widget.
2991
	 * Creates a new <code>Text</code> widget.
2968
	 *
2992
	 *
Lines 2997-3003 Link Here
2997
3021
2998
		return text;
3022
		return text;
2999
	}
3023
	}
3000
	
3024
3001
	protected final Text addText(
3025
	protected final Text addText(
3002
			Composite container,
3026
			Composite container,
3003
			WritablePropertyValueModel<String> textHolder,
3027
			WritablePropertyValueModel<String> textHolder,
Lines 3010-3017 Link Here
3010
	}
3034
	}
3011
3035
3012
	/**
3036
	/**
3013
	 * Creates a new unmanaged <code>Text</code> widget.  Unmanaged means 
3037
	 * Creates a new unmanaged <code>Text</code> widget.  Unmanaged means
3014
	 * that this Pane will not handle the enabling/disabling of this widget.  
3038
	 * that this Pane will not handle the enabling/disabling of this widget.
3015
	 * The owning object will handle it with its own PaneEnabler or ControlEnabler.
3039
	 * The owning object will handle it with its own PaneEnabler or ControlEnabler.
3016
	 *
3040
	 *
3017
	 * @param container The parent container
3041
	 * @param container The parent container
Lines 3060-3066 Link Here
3060
3084
3061
		return addTitledGroup(container, title, 1, helpId);
3085
		return addTitledGroup(container, title, 1, helpId);
3062
	}
3086
	}
3063
	
3087
3064
	/**
3088
	/**
3065
	 * Creates a new container with a titled border.
3089
	 * Creates a new container with a titled border.
3066
	 *
3090
	 *
Lines 3077-3083 Link Here
3077
	                                      String helpId) {
3101
	                                      String helpId) {
3078
3102
3079
		Group group = this.widgetFactory.createGroup(container, title);
3103
		Group group = this.widgetFactory.createGroup(container, title);
3080
		//manageWidget(group); TODO unsure if I want to manage groups, 
3104
		//manageWidget(group); TODO unsure if I want to manage groups,
3081
		//also should probably rename this addUnmanagedTitledPane
3105
		//also should probably rename this addUnmanagedTitledPane
3082
		group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
3106
		group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
3083
3107
Lines 3098-3106 Link Here
3098
	}
3122
	}
3099
3123
3100
	/**
3124
	/**
3101
	 * Creates a new unmanaged new toggle button (radio button or check box).  
3125
	 * Creates a new unmanaged new toggle button (radio button or check box).
3102
	 * Unmanaged means  that this Pane will not handle the enabling/disabling 
3126
	 * Unmanaged means  that this Pane will not handle the enabling/disabling
3103
	 * of this widget. The owning object will handle it with its own PaneEnabler 
3127
	 * of this widget. The owning object will handle it with its own PaneEnabler
3104
	 * or ControlEnabler.
3128
	 * or ControlEnabler.
3105
	 *
3129
	 *
3106
	 * @param parent The parent container
3130
	 * @param parent The parent container
Lines 3117-3125 Link Here
3117
	        WritablePropertyValueModel<Boolean> booleanHolder,
3141
	        WritablePropertyValueModel<Boolean> booleanHolder,
3118
	        String helpId,
3142
	        String helpId,
3119
	        int toggleButtonType) {
3143
	        int toggleButtonType) {
3120
		
3144
3121
		Button button;
3145
		Button button;
3122
		
3146
3123
		if (toggleButtonType == SWT.PUSH) {
3147
		if (toggleButtonType == SWT.PUSH) {
3124
			button = this.widgetFactory.createPushButton(parent, buttonText);
3148
			button = this.widgetFactory.createPushButton(parent, buttonText);
3125
		}
3149
		}
Lines 3132-3148 Link Here
3132
		else {
3156
		else {
3133
			button = this.widgetFactory.createButton(parent, buttonText);
3157
			button = this.widgetFactory.createButton(parent, buttonText);
3134
		}
3158
		}
3135
		
3159
3136
		button.setLayoutData(new GridData());
3160
		button.setLayoutData(new GridData());
3137
		SWTTools.bind(booleanHolder, button);
3161
		SWTTools.bind(booleanHolder, button);
3138
		
3162
3139
		if (helpId != null) {
3163
		if (helpId != null) {
3140
			getHelpSystem().setHelp(button, helpId);
3164
			getHelpSystem().setHelp(button, helpId);
3141
		}
3165
		}
3142
		
3166
3143
		return button;
3167
		return button;
3144
	}
3168
	}
3145
	
3169
3146
	/**
3170
	/**
3147
	 * Creates a new toggle button (radio button or check box) using the given
3171
	 * Creates a new toggle button (radio button or check box) using the given
3148
	 * information.
3172
	 * information.
Lines 3161-3172 Link Here
3161
	        WritablePropertyValueModel<Boolean> booleanHolder,
3185
	        WritablePropertyValueModel<Boolean> booleanHolder,
3162
	        String helpId,
3186
	        String helpId,
3163
	        int toggleButtonType) {
3187
	        int toggleButtonType) {
3164
		
3188
3165
		Button button = addUnmanagedToggleButton(
3189
		Button button = addUnmanagedToggleButton(
3166
				parent, 
3190
				parent,
3167
				buttonText, 
3191
				buttonText,
3168
				booleanHolder, 
3192
				booleanHolder,
3169
				helpId, 
3193
				helpId,
3170
				toggleButtonType);
3194
				toggleButtonType);
3171
		this.manageWidget(button);
3195
		this.manageWidget(button);
3172
		return button;
3196
		return button;
Lines 3254-3260 Link Here
3254
	protected void doPopulate() {
3278
	protected void doPopulate() {
3255
		this.log(Tracing.UI_LAYOUT, "   ->doPopulate()");
3279
		this.log(Tracing.UI_LAYOUT, "   ->doPopulate()");
3256
	}
3280
	}
3257
	
3281
3258
	private void controlEnabledState(PropertyValueModel<Boolean> booleanModel, Control... controls) {
3282
	private void controlEnabledState(PropertyValueModel<Boolean> booleanModel, Control... controls) {
3259
		this.controlEnabledState_(this.wrapEnabledModel(booleanModel), controls);
3283
		this.controlEnabledState_(this.wrapEnabledModel(booleanModel), controls);
3260
	}
3284
	}
Lines 3266-3293 Link Here
3266
	private PropertyValueModel<Boolean> wrapEnabledModel(PropertyValueModel<Boolean> booleanModel) {
3290
	private PropertyValueModel<Boolean> wrapEnabledModel(PropertyValueModel<Boolean> booleanModel) {
3267
		return new TransformationPropertyValueModel<Boolean, Boolean>(booleanModel, NonNullBooleanTransformer.FALSE);
3291
		return new TransformationPropertyValueModel<Boolean, Boolean>(booleanModel, NonNullBooleanTransformer.FALSE);
3268
	}
3292
	}
3269
	
3293
3270
	private void controlEnabledState_(PropertyValueModel<Boolean> booleanModel, Control... controls) {
3294
	private void controlEnabledState_(PropertyValueModel<Boolean> booleanModel, Control... controls) {
3271
		SWTTools.controlEnabledState(this.andEnabledModel(booleanModel), controls);
3295
		SWTTools.controlEnabledState(this.andEnabledModel(booleanModel), controls);
3272
	}
3296
	}
3273
	
3297
3274
	private PropertyValueModel<Boolean> getCombinedEnabledModel() {
3298
	private PropertyValueModel<Boolean> getCombinedEnabledModel() {
3275
		return (this.combinedEnabledModel != null) ? this.combinedEnabledModel : this.baseEnabledModel;
3299
		return (this.combinedEnabledModel != null) ? this.combinedEnabledModel : this.baseEnabledModel;
3276
	}
3300
	}
3277
	
3301
3278
	private boolean getCombinedEnablement() {
3302
	private boolean getCombinedEnablement() {
3279
		Boolean enabled = getCombinedEnabledModel().getValue();
3303
		Boolean enabled = getCombinedEnabledModel().getValue();
3280
		return (enabled == null) ? true : enabled.booleanValue();
3304
		return (enabled == null) ? true : enabled.booleanValue();
3281
	}
3305
	}
3282
	
3306
3283
	private PropertyValueModel<Boolean> andEnabledModel(PropertyValueModel<Boolean> booleanModel) {
3307
	private PropertyValueModel<Boolean> andEnabledModel(PropertyValueModel<Boolean> booleanModel) {
3284
		return CompositeBooleanPropertyValueModel.and(getCombinedEnabledModel(), booleanModel);
3308
		return CompositeBooleanPropertyValueModel.and(getCombinedEnabledModel(), booleanModel);
3285
	}
3309
	}
3286
	
3310
3287
	protected void controllerEnablementChanged() {
3311
	protected void controllerEnablementChanged() {
3288
		enableWidgets_(getCombinedEnablement());
3312
		enableWidgets_(getCombinedEnablement());
3289
	}
3313
	}
3290
	
3314
3291
	/**
3315
	/**
3292
	 * Changes the enablement state of the widgets of this pane.
3316
	 * Changes the enablement state of the widgets of this pane.
3293
	 *
3317
	 *
Lines 3300-3322 Link Here
3300
		this.baseEnabledModel.setValue(Boolean.valueOf(enabled));
3324
		this.baseEnabledModel.setValue(Boolean.valueOf(enabled));
3301
		enableWidgets_(getCombinedEnablement());
3325
		enableWidgets_(getCombinedEnablement());
3302
	}
3326
	}
3303
	
3327
3304
	private void enableWidgets_(boolean enabled) {
3328
	private void enableWidgets_(boolean enabled) {
3305
		if (! this.container.isDisposed()) {
3329
		if (! this.container.isDisposed()) {
3306
			for (Control control : this.managedWidgets) {
3330
			for (Control control : this.managedWidgets) {
3307
				control.setEnabled(enabled);
3331
				control.setEnabled(enabled);
3308
			}
3332
			}
3309
			
3333
3310
			for (Pane<?> subPane : this.managedSubPanes) {
3334
			for (Pane<?> subPane : this.managedSubPanes) {
3311
				subPane.enableWidgets(enabled);
3335
				subPane.enableWidgets(enabled);
3312
			}
3336
			}
3313
		}
3337
		}
3314
	}
3338
	}
3315
	
3339
3316
	private void engageSubjectHolder() {
3340
	private void engageSubjectHolder() {
3317
		this.subjectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.subjectChangeListener);
3341
		this.subjectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.subjectChangeListener);
3318
	}
3342
	}
3319
	
3343
3320
	/**
3344
	/**
3321
	 * engage the specified subject
3345
	 * engage the specified subject
3322
	 */
3346
	 */
Lines 3698-3715 Link Here
3698
			}
3722
			}
3699
		}
3723
		}
3700
	}
3724
	}
3701
	
3725
3702
	public void dispose() {
3726
	public void dispose() {
3703
		this.log(Tracing.UI_LAYOUT, "dispose()");
3727
		this.log(Tracing.UI_LAYOUT, "dispose()");
3704
3728
3705
		// Dispose this pane
3729
		// Dispose this pane
3706
		this.disengageListeners(getSubject());
3730
		this.disengageListeners(getSubject());
3707
		this.disengageSubjectHolder();
3731
		this.disengageSubjectHolder();
3708
		
3732
3709
		if (this.combinedEnabledModel != null && this.combinedEnabledModelListener != null) {
3733
		if (this.combinedEnabledModel != null && this.combinedEnabledModelListener != null) {
3710
			this.combinedEnabledModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.combinedEnabledModelListener);
3734
			this.combinedEnabledModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.combinedEnabledModelListener);
3711
		}
3735
		}
3712
		
3736
3713
		this.leftControlAligner.dispose();
3737
		this.leftControlAligner.dispose();
3714
		this.rightControlAligner.dispose();
3738
		this.rightControlAligner.dispose();
3715
3739
(-)META-INF/MANIFEST.MF (+2 lines)
Lines 25-30 Link Here
25
 org.eclipse.jst.common.project.facet.core;bundle-version="[1.3.100,2.0.0)",
25
 org.eclipse.jst.common.project.facet.core;bundle-version="[1.3.100,2.0.0)",
26
 org.eclipse.jst.j2ee;bundle-version="[1.1.200,2.0.0)",
26
 org.eclipse.jst.j2ee;bundle-version="[1.1.200,2.0.0)",
27
 org.eclipse.jst.j2ee.core;bundle-version="[1.1.200,2.0.0)",
27
 org.eclipse.jst.j2ee.core;bundle-version="[1.1.200,2.0.0)",
28
 org.eclipse.persistence.jpa.jpql;bundle-version="1.0.0",
28
 org.eclipse.wst.common.emf;bundle-version="[1.1.200,2.0.0)",
29
 org.eclipse.wst.common.emf;bundle-version="[1.1.200,2.0.0)",
29
 org.eclipse.wst.common.emfworkbench.integration;bundle-version="[1.1.200,2.0.0)",
30
 org.eclipse.wst.common.emfworkbench.integration;bundle-version="[1.1.200,2.0.0)",
30
 org.eclipse.wst.common.frameworks;bundle-version="[1.1.200,2.0.0)",
31
 org.eclipse.wst.common.frameworks;bundle-version="[1.1.200,2.0.0)",
Lines 62-67 Link Here
62
 org.eclipse.jpt.jpa.core.internal.jpa2.resource.java;x-internal:=true,
63
 org.eclipse.jpt.jpa.core.internal.jpa2.resource.java;x-internal:=true,
63
 org.eclipse.jpt.jpa.core.internal.jpa2.resource.java.binary;x-internal:=true,
64
 org.eclipse.jpt.jpa.core.internal.jpa2.resource.java.binary;x-internal:=true,
64
 org.eclipse.jpt.jpa.core.internal.jpa2.resource.java.source;x-internal:=true,
65
 org.eclipse.jpt.jpa.core.internal.jpa2.resource.java.source;x-internal:=true,
66
 org.eclipse.jpt.jpa.core.internal.jpql;x-friends:="org.eclipse.jpt.jpa.ui",
65
 org.eclipse.jpt.jpa.core.internal.libprov;x-internal:=true,
67
 org.eclipse.jpt.jpa.core.internal.libprov;x-internal:=true,
66
 org.eclipse.jpt.jpa.core.internal.libval;x-internal:=true,
68
 org.eclipse.jpt.jpa.core.internal.libval;x-internal:=true,
67
 org.eclipse.jpt.jpa.core.internal.operations;x-internal:=true,
69
 org.eclipse.jpt.jpa.core.internal.operations;x-internal:=true,
(-)property_files/jpa_jpql_validation.properties (+484 lines)
Added Link Here
1
################################################################################
2
# Copyright (c) 2011 Oracle. All rights reserved.
3
# This program and the accompanying materials are made available under the
4
# terms of the Eclipse Public License v1.0, which accompanies this distribution
5
# and is available at http:#www.eclipse.org/legal/epl-v10.html.
6
# 
7
# Contributors:
8
#     Oracle - initial API and implementation
9
################################################################################
10
11
# AbsExpression - Grammar
12
ABS_EXPRESSION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
13
ABS_EXPRESSION_MISSING_EXPRESSION = The encapsulated expression must be provided for an ABS expression.
14
ABS_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the ABS expression.
15
ABS_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the ABS expression.
16
# AbsExpression - Semantic
17
ABS_EXPRESSION_INVALID_NUMERIC_EXPRESSION = The encapsulated expression is not a valid numeric expression.
18
19
# AbstractFromClause - Grammar
20
ABSTRACT_FROM_CLAUSE_IDENTIFICATION_VARIABLE_DECLARATION_ENDS_WITH_COMMA = The FROM clause cannot end with a comma.
21
ABSTRACT_FROM_CLAUSE_IDENTIFICATION_VARIABLE_DECLARATION_IS_MISSING_COMMA = The FROM clause has ''{0}'' and ''{1}'' that are not separated by a comma.
22
ABSTRACT_FROM_CLAUSE_MISSING_IDENTIFICATION_VARIABLE_DECLARATION = The FROM clause must defined at least one identification variable declaration.
23
ABSTRACT_FROM_CLAUSE_WRONG_ORDER_OF_IDENTIFICATION_VARIABLE_DECLARATION = The identification variable ''{0}'' is declared after its usage. Identification variables are evaluated from left to right.
24
25
# AbstractPathExpression - Grammar
26
ABSTRACT_PATH_EXPRESSION_CANNOT_END_WITH_COMMA = A path expression cannot end with a comma.
27
ABSTRACT_PATH_EXPRESSION_MISSING_IDENTIFICATION_VARIABLE = A path expression must start with an identification variable.
28
29
# AbstractSchemaName - Grammar
30
ABSTRACT_SCHEMA_NAME_INVALID = The abstract schema type ''{0}'' is unknown.
31
ABSTRACT_SCHEMA_NAME_NOT_RESOLVABLE = ''{0}'' cannot be resolved to a type.
32
# AbstractSchemaName - Semantic
33
PATH_EXPRESSION_NOT_RELATIONSHIP_MAPPING = The derived path ''{0}'' does not represent an association field.
34
35
# AbstractSelectClause - Grammar
36
ABSTRACT_SELECT_CLAUSE_SELECT_EXPRESSION_ENDS_WITH_COMMA = The select expression cannot end with a comma.
37
ABSTRACT_SELECT_CLAUSE_SELECT_EXPRESSION_IS_MISSING_COMMA = The SELECT clause has ''{0}'' and ''{1}'' that are not separated by a comma.
38
ABSTRACT_SELECT_CLAUSE_SELECT_EXPRESSION_MALFORMED = The select expression is malformed.
39
ABSTRACT_SELECT_CLAUSE_SELECT_MISSING_EXPRESSION = The select expression is missing from the SELECT clause.
40
41
# AbstractSelectStatement - Grammar
42
ABSTRACT_SELECT_STATEMENT_FROM_CLAUSE_MSSING = A select statement must have a FROM clause.
43
44
# AdditionExpression - Semantic
45
ADDITION_EXPRESSION_LEFT_EXPRESSION_WRONG_TYPE = The left side of the addition is not a valid arithmetic expression.
46
ADDITION_EXPRESSION_RIGHT_EXPRESSION_WRONG_TYPE = The right side of the addition is not a valid arithmetic expression.
47
48
# AllOrAnyExpression - Grammar
49
ALL_OR_ANY_EXPRESSION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
50
ALL_OR_ANY_EXPRESSION_MISSING_EXPRESSION = The subquery must be provided for an {0} expression.
51
ALL_OR_ANY_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the {0} expression.
52
ALL_OR_ANY_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the {0} expression.
53
ALL_OR_ANY_EXPRESSION_NOT_PART_OF_COMPARISON_EXPRESSION = The {0} expression must be part of a comparison expression.
54
55
# ArithmeticFactor - Grammar
56
ARITHMETIC_FACTOR_MISSING_EXPRESSION = An arithmetic factor must be followed by an expression.
57
# ArithmeticFactor - Semantic
58
ARITHMETIC_FACTOR_INVALID_EXPRESSION = The expression must be an arithmetic expression.
59
60
# ArithmeticExpression - Grammar
61
ARITHMETIC_EXPRESSION_INVALID_LEFT_EXPRESSION = The left expression is not an arithmetic expression.
62
ARITHMETIC_EXPRESSION_INVALID_RIGHT_EXPRESSION = The right expression is not an arithmetic expression.
63
ARITHMETIC_EXPRESSION_MISSING_LEFT_EXPRESSION = The left expression is missing from the arithmetic expression.
64
ARITHMETIC_EXPRESSION_MISSING_RIGHT_EXPRESSION = The right expression is missing from the arithmetic expression.
65
66
# AvgFunction - Grammar
67
AVG_FUNCTION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
68
AVG_FUNCTION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the AVG expression.
69
AVG_FUNCTION_MISSING_EXPRESSION = The encapsulated expression must be provided for an AVG expression.
70
AVG_FUNCTION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the AVG expression.
71
# AvgFunction - Semantic
72
AVG_FUNCTION_INVALID_NUMERIC_EXPRESSION = The encapsulated expression is not a valid numeric expression.
73
74
# BetweenExpression - Grammar
75
BETWEEN_EXPRESSION_MISSING_EXPRESSION = The result expression is missing from the BETWEEN expression.
76
BETWEEN_EXPRESSION_MISSING_LOWER_BOUND_EXPRESSION = The lower bound expression is missing from the BETWEEN expression.
77
BETWEEN_EXPRESSION_MISSING_AND = The identifier AND is missing from the BETWEEN expression.
78
BETWEEN_EXPRESSION_MISSING_UPPER_BOUND_EXPRESSION = The upper bound expression is missing from the BETWEEN expression.
79
# BetweenExpression - Semantic
80
BETWEEN_EXPRESSION_WRONG_TYPE = The expression's type and the lower and upper bound expressions' type have to be the same type.
81
82
# CaseExpression - Grammar
83
CASE_EXPRESSION_MISSING_ELSE_EXPRESSION = A CASE expression must have an ELSE expression.
84
CASE_EXPRESSION_MISSING_ELSE_IDENTIFIER = The identifier ELSE is missing from the CASE expression.
85
CASE_EXPRESSION_MISSING_END_IDENTIFIER = The identifier END is missing from the CASE expression.
86
CASE_EXPRESSION_MISSING_WHEN_CLAUSE = A CASE expression must define at least one WHEN clause.
87
CASE_EXPRESSION_WHEN_CLAUSES_END_WITH_COMMA = The WHEN clauses cannot end with a comma.
88
CASE_EXPRESSION_WHEN_CLAUSES_HAS_COMMA = Two WHEN clauses cannot be separated by a comma.
89
90
# CoalesceExpression - Grammar
91
COALESCE_EXPRESSION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
92
COALESCE_EXPRESSION_MISSING_EXPRESSION = The encapsulated expressions must be provided for a COALESCE expression.
93
COALESCE_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the COALESCE expression.
94
COALESCE_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the COALESCE expression.
95
96
# CollectionExpression - Grammar
97
COLLECTION_EXPRESSION_MISSING_EXPRESSION = An expression at position {0} must be defined.
98
99
# CollectionMemberExpression - Grammar
100
COLLECTION_MEMBER_EXPRESSION_MISSING_ENTITY_EXPRESSION = A collection member expression must define an entity expression.
101
COLLECTION_MEMBER_EXPRESSION_MISSING_COLLECTION_VALUED_PATH_EXPRESSION = A collection member expression must define a collection valued path expression.
102
# CollectionMemberExpression - Semantic
103
COLLECTION_MEMBER_EXPRESSION_EMBEDDABLE = An embeddable type is not supported.
104
105
# CollectionMemberDeclaration - Grammar
106
COLLECTION_MEMBER_DECLARATION_MISSING_COLLECTION_VALUED_PATH_EXPRESSION = The collection-valued path expression is missing from the collection member declaration.
107
COLLECTION_MEMBER_DECLARATION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the collection member declaration.
108
COLLECTION_MEMBER_DECLARATION_MISSING_IDENTIFICATION_VARIABLE = An identification variable must be specified for a collection member declaration.
109
COLLECTION_MEMBER_DECLARATION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the collection member declaration.
110
111
# CollectionValuedPathExpression - Semantic
112
COLLECTION_VALUED_PATH_EXPRESSION_NOT_RESOLVABLE" ,     "The collection-valued path ''{0}'' cannot be resolved to a valid association field.
113
COLLECTION_VALUED_PATH_EXPRESSION_NOT_COLLECTION_TYPE = The collection-valued path ''{0}'' must resolve to an association field.
114
115
# ComparisonExpression - Grammar
116
COMPARISON_EXPRESSION_MISSING_LEFT_EXPRESSION = A comparison expression must define the left side of the comparison.
117
COMPARISON_EXPRESSION_MISSING_RIGHT_EXPRESSION = A comparison expression must define the right side of the comparison.
118
# ComparisonExpression - Semantic
119
COMPARISON_EXPRESSION_WRONG_COMPARISON_TYPE = The left and right expressions' type must be of the same type.
120
121
# ConcatExpression - Grammar
122
CONCAT_EXPRESSION_INVALID_EXPRESSION = The expression ''{0}'' is not valid expression.
123
CONCAT_EXPRESSION_MISSING_EXPRESSION = The encapsulated expression is missing from the CONCAT expression.
124
CONCAT_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the CONCAT expression.
125
CONCAT_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the CONCAT expression.
126
# ConcatExpression - Semantic
127
CONCAT_EXPRESSION_EXPRESSION_WRONG_TYPE = The expression ''{0}'' is not a String.
128
129
# ConstructorExpression - Grammar
130
CONSTRUCTOR_EXPRESSION_CONSTRUCTOR_ITEM_ENDS_WITH_COMMA = The constructor items cannot end with a comma.
131
CONSTRUCTOR_EXPRESSION_CONSTRUCTOR_ITEM_IS_MISSING_COMMA = The constructor expression has two constructor items (''{0}'' and ''{1}'') that are not separated by a comma.
132
CONSTRUCTOR_EXPRESSION_MISSING_CONSTRUCTOR_ITEM = A constructor expression must define at least one constructor item.
133
CONSTRUCTOR_EXPRESSION_MISSING_CONSTRUCTOR_NAME = The fully qualified class name must be specified.
134
CONSTRUCTOR_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the constructor expression.
135
CONSTRUCTOR_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the constructor expression.
136
# ConstructorExpression - Semantic
137
CONSTRUCTOR_EXPRESSION_MISMATCHED_PARAMETER_TYPES = No constructors can be found that match the argument types.
138
CONSTRUCTOR_EXPRESSION_UNKNOWN_TYPE = ''{0}'' cannot be resolved to a type.
139
140
# CountFunction - Grammar
141
COUNT_FUNCTION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
142
COUNT_FUNCTION_MISSING_EXPRESSION = The encapsulated expression must be provided for a COUNT expression.
143
COUNT_FUNCTION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the COUNT expression.
144
COUNT_FUNCTION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the COUNT expression.
145
# CountFunction - Semantic
146
COUNT_FUNCTION_DISTINCT_EMBEDDABLE = The use of DISTINCT is not supported for arguments of embeddable types.
147
148
# DateTime - Grammar
149
DATE_TIME_JDBC_ESCAPE_FORMAT_INVALID_SPECIFICATION = The JDBC escape format does not start with either 'd', 't' or 'ts'.
150
DATE_TIME_JDBC_ESCAPE_FORMAT_MISSING_CLOSE_QUOTE = The JDBC escape format is missing the close quote.
151
DATE_TIME_JDBC_ESCAPE_FORMAT_MISSING_OPEN_QUOTE = The JDBC escape format is missing the open quote.
152
DATE_TIME_JDBC_ESCAPE_FORMAT_MISSING_RIGHT_CURLY_BRACE = The JDBC escape format is missing the right curly brace.
153
154
# DeleteClause - Grammar
155
DELETE_CLAUSE_FROM_MISSING = The identifier FROM is missing from the DELETE FROM clause.
156
DELETE_CLAUSE_MULTIPLE_RANGE_VARIABLE_DECLARATION = Only one entity abstract schema type can be defined.
157
DELETE_CLAUSE_RANGE_VARIABLE_DECLARATION_MALFORMED = The entity abstract schema type declaration is malformed.
158
DELETE_CLAUSE_RANGE_VARIABLE_DECLARATION_MISSING = A DELETE clause must define an entity abstract schema type.
159
160
# DivisionExpression - Semantic
161
DIVISION_EXPRESSION_LEFT_EXPRESSION_WRONG_TYPE = The left side of the division is not a valid arithmetic expression.
162
DIVISION_EXPRESSION_RIGHT_EXPRESSION_WRONG_TYPE = The right side of the division is not a valid arithmetic expression.
163
164
# EclipseLinkQueryBuilder - Validation
165
ECLIPSE_LINK_QUERY_BUILDER_GRAMMAR_VALIDATOR_ERROR_MESSAGE = Syntax error parsing the query [{0}]. {1}
166
ECLIPSE_LINK_QUERY_BUILDER_SEMANTIC_VALIDATOR_ERROR_MESSAGE = Problem compiling the query [{0}]. {1}
167
168
# EncapsulatedIdentificationVariableExpression - Semantic
169
ENCAPSULATED_IDENTIFICATION_VARIABLE_EXPRESSION_NOT_MAP_VALUED = The {0} operator may only be applied to identification variables that correspond to map-valued associations or map-valued element collections.
170
171
# EmptyCollectionComparisonExpression - Grammar
172
EMPTY_COLLECTION_COMPARISON_EXPRESSION_MISSING_EXPRESSION = The collection valued path expression must be defined.
173
174
# EntityTypeLiteral - Semantic
175
ENTITY_TYPE_LITERAL_NOT_RESOLVABLE = ''{0}'' cannot be resolved to a type.
176
177
# EntryExpression - Grammar
178
ENTRY_EXPRESSION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
179
ENTRY_EXPRESSION_MISSING_EXPRESSION = An identification variable must be provided for an ENTRY expression.
180
ENTRY_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the ENTRY expression.
181
ENTRY_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the ENTRY expression.
182
183
# ExistsExpression - Grammar
184
EXISTS_EXPRESSION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
185
EXISTS_EXPRESSION_MISSING_EXPRESSION = A subquery must be provided for an EXISTS expression.
186
EXISTS_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the EXISTS expression.
187
EXISTS_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the EXISTS expression.
188
189
# FuncExpression - Grammar
190
FUNC_EXPRESSION_MISSING_FUNCTION_NAME = The SQL function name must be specified.
191
FUNC_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the FUNC expression.
192
FUNC_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the FUNC expression.
193
194
# GroupByClause - Grammar
195
GROUP_BY_CLAUSE_GROUP_BY_ITEM_ENDS_WITH_COMMA = The select expression cannot end with a comma.
196
GROUP_BY_CLAUSE_GROUP_BY_ITEM_IS_MISSING_COMMA = The GROUP BY clause has ''{0}'' and ''{1}'' that are not separated by a comma.
197
GROUP_BY_CLAUSE_GROUP_BY_ITEM_MISSING = The grouping item is missing from the GROUP BY clause.
198
199
# HavingClause - Grammar
200
HAVING_CLAUSE_INVALID_CONDITIONAL_EXPRESSION = The expression is not a valid conditional expression.
201
HAVING_CLAUSE_MISSING_CONDITIONAL_EXPRESSION = The conditional expression is missing from the HAVING clause.
202
203
# IdentificationVariable - Grammar
204
IDENTIFICATION_VARIABLE_INVALID_DUPLICATE = The identification variable ''{0}'' cannot be declared more than once.
205
IDENTIFICATION_VARIABLE_INVALID_JAVA_IDENTIFIER = The identification variable ''{0}'' is not following the rules for a Java identifier.
206
IDENTIFICATION_VARIABLE_INVALID_RESERVED_WORD = The identification variable ''{0}'' cannot be a reserved word.
207
# IdentificationVariable - Semantic
208
IDENTIFICATION_VARIABLE_ENTITY_NAME = An identification variable must not have the same name as any entity in the same persistence unit.
209
IDENTIFICATION_VARIABLE_INVALID_NOT_DECLARED = The identification variable ''{0}'' is not defined in the FROM clause.
210
211
# IdentificationVariableDeclaration - Grammar
212
IDENTIFICATION_VARIABLE_DECLARATION_MISSING_RANGE_VARIABLE_DECLARATION = The range variable declaration must be specified.
213
214
# IndexExpression - Grammar
215
INDEX_EXPRESSION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
216
INDEX_EXPRESSION_MISSING_EXPRESSION = An identification variable must be provided for an INDEX expression.
217
INDEX_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the INDEX expression.
218
INDEX_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the INDEX expression.
219
# IndexExpression - Semantic
220
INDEX_EXPRESSION_WRONG_VARIABLE = The identification variable ''{0}'' does not represent an association or element collection.
221
222
# InExpression - Grammar
223
IN_EXPRESSION_IN_ITEM_ENDS_WITH_COMMA = The items cannot end with a comma.
224
IN_EXPRESSION_IN_ITEM_IS_MISSING_COMMA = The IN expression has ''{0}'' and ''{1}'' that are not separated by a comma.
225
IN_EXPRESSION_MALFORMED_EXPRESSION = The IN expression does not have a valid state field path expression or TYPE expession.
226
IN_EXPRESSION_MISSING_IN_ITEMS = A least one item must be defined for the IN expression.
227
IN_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the IN expression.
228
IN_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the IN expression.
229
IN_EXPRESSION_MISSING_EXPRESSION = A state field path expression or TYPE expression must be defined.
230
231
# InputParameter - Grammar
232
INPUT_PARAMETER_JAVA_IDENTIFIER = The named input parameter ''{0}'' is not following the rules for a Java identifier.
233
INPUT_PARAMETER_MISSING_PARAMETER = The parameter value is missing from the input parameter.
234
INPUT_PARAMETER_MIXTURE = Named and positional input parameters must not be mixed in a single query.
235
INPUT_PARAMETER_NOT_INTEGER = The positional input parameter ''{0}'' cannot use non-Integer characters.
236
INPUT_PARAMETER_SMALLER_THAN_ONE = The number used for the positional input parameter ''{0}'' must be greater than 0.
237
INPUT_PARAMETER_WRONG_CLAUSE_DECLARATION = Input parameters can only be used in the WHERE clause or HAVING clause of a query.
238
239
# Join - Grammar
240
JOIN_MISSING_IDENTIFICATION_VARIABLE = An identification variable must be defined for a JOIN expression.
241
JOIN_MISSING_JOIN_ASSOCIATION_PATH = The join association path is missing from the JOIN expression.
242
243
# JoinFetch - Grammar
244
JOIN_FETCH_MISSING_JOIN_ASSOCIATION_PATH = The join association path is missing from the JOIN FETCH expression.
245
JOIN_FETCH_WRONG_CLAUSE_DECLARATION = JOIN FETCH expressions cannot be used in a FROM clause of a subquery.
246
247
# JPQLExpression - Grammar
248
JPQL_EXPRESSION_INVALID_QUERY = The query does not start with a valid identifier, has to be either SELECT, UPDATE or DELETE FROM.
249
JPQL_EXPRESSION_UNKNOWN_ENDING = The query contains a malformed ending.
250
251
# KeyExpression - Grammar
252
KEY_EXPRESSION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
253
KEY_EXPRESSION_MISSING_EXPRESSION = The identification variable must be provided for an ABS expression.
254
KEY_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the ABS expression.
255
KEY_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the ABS expression.
256
257
# LengthExpression - Grammar
258
LENGTH_EXPRESSION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
259
LENGTH_EXPRESSION_MISSING_EXPRESSION = An expression must be provided for a LENGTH expression.
260
LENGTH_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the LENGTH expression.
261
LENGTH_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the LENGTH expression.
262
# LikeExpression - Semantic
263
LENGTH_EXPRESSION_WRONG_TYPE = The encapsulated expression is not of string type.
264
265
# LikeExpression - Grammar
266
LIKE_EXPRESSION_INVALID_ESCAPE_CHARACTER = {0} is not a valid escape character.
267
LIKE_EXPRESSION_MISSING_ESCAPE_CHARACTER = The escape character is missing from the LIKE expression.
268
LIKE_EXPRESSION_MISSING_PATTERN_VALUE = The pattern value is missing from the LIKE expression.
269
LIKE_EXPRESSION_MISSING_STRING_EXPRESSION = The string expression is missing from the LIKE expression.
270
271
# LocateExpression - Grammar
272
LOCATE_EXPRESSION_INVALID_FIRST_EXPRESSION = The first argument is not a valid expression.
273
LOCATE_EXPRESSION_INVALID_SECOND_EXPRESSION = The second argument is not a valid expression.
274
LOCATE_EXPRESSION_INVALID_THIRD_EXPRESSION = The third argument is not a valid expression.
275
LOCATE_EXPRESSION_MISSING_FIRST_EXPRESSION = The first argument is missing from the LOCATE expression.
276
LOCATE_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the LOCATE expression.
277
LOCATE_EXPRESSION_MISSING_FIRST_COMMA = The first comma is missing from the LOCATE expression.
278
LOCATE_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the LOCATE expression.
279
LOCATE_EXPRESSION_MISSING_SECOND_COMMA = The second comma is missing from the LOCATE expression.
280
LOCATE_EXPRESSION_MISSING_SECOND_EXPRESSION = The second argument is missing from the LOCATE expression.
281
LOCATE_EXPRESSION_MISSING_THIRD_EXPRESSION = The third argument is missing from the LOCATE expression.
282
# LocateExpression - Semantic
283
LOCATE_EXPRESSION_FIRST_EXPRESSION_WRONG_TYPE = The first expression is not of string type.
284
LOCATE_EXPRESSION_SECOND_EXPRESSION_WRONG_TYPE = The second expression is not of string type.
285
LOCATE_EXPRESSION_THIRD_EXPRESSION_WRONG_TYPE = The third encapsulated expression is not of numeric type.
286
287
# LogicalExpression - Grammar
288
LOGICAL_EXPRESSION_INVALID_LEFT_EXPRESSION = The left expression is missing from the logical expression.
289
LOGICAL_EXPRESSION_INVALID_RIGHT_EXPRESSION = The right expression is missing from the logical expression.
290
LOGICAL_EXPRESSION_MISSING_LEFT_EXPRESSION = The left expression is not a valid expression.
291
LOGICAL_EXPRESSION_MISSING_RIGHT_EXPRESSION = The right expression is not a valid expression.
292
293
# LowerExpression - Grammar
294
LOWER_EXPRESSION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
295
LOWER_EXPRESSION_MISSING_EXPRESSION = An expression must be provided for a LOWER expression.
296
LOWER_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the LOWER expression.
297
LOWER_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the LOWER expression.
298
# UpperExpression - Semantic
299
LOWER_EXPRESSION_WRONG_TYPE = The expression is not a String.
300
301
# MaxFunction - Grammar
302
MAX_FUNCTION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
303
MAX_FUNCTION_MISSING_EXPRESSION = The encapsulated expression must be provided for a MAX expression.
304
MAX_FUNCTION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the MAX expression.
305
MAX_FUNCTION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the MAX expression.
306
307
# MinFunction - Grammar
308
MIN_FUNCTION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
309
MIN_FUNCTION_MISSING_EXPRESSION = The encapsulated expression must be provided for a MIN expression.
310
MIN_FUNCTION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the MIN expression.
311
MIN_FUNCTION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the MIN expression.
312
313
# ModExpression - Grammar
314
MOD_EXPRESSION_INVALID_FIRST_EXPRESSION = The first argument is not a valid expression.
315
MOD_EXPRESSION_INVALID_SECOND_PARENTHESIS = The second argument is not a valid expression.
316
MOD_EXPRESSION_MISSING_COMMA = The comma is missing from the MOD expression.
317
MOD_EXPRESSION_MISSING_FIRST_EXPRESSION = The first argument is missing from the MOD expression.
318
MOD_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the MOD expression.
319
MOD_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the MOD expression.
320
MOD_EXPRESSION_MISSING_SECOND_EXPRESSION = The second argument is missing from the MOD expression.
321
# ModExpression - Semantic
322
MOD_EXPRESSION_FIRST_EXPRESSION_WRONG_TYPE = The first expression is not an Integer.
323
MOD_EXPRESSION_SECOND_EXPRESSION_WRONG_TYPE = The second expression is not an Integer.
324
325
# MultiplicationExpression - Semantic
326
MULTIPLICATION_EXPRESSION_LEFT_EXPRESSION_WRONG_TYPE = The left side of the multiplication is not a valid arithmetic expression.
327
MULTIPLICATION_EXPRESSION_RIGHT_EXPRESSION_WRONG_TYPE = The right side of the multiplication is not a valid arithmetic expression.
328
329
# NotExpression - Grammar
330
NOT_EXPRESSION_MISSING_EXPRESSION = The expression is missing after the identifier NOT.
331
# NotExpression - Semantic
332
NOT_EXPRESSION_WRONG_TYPE = The expression is not of boolean type.
333
334
# NullComparisonExpression - Grammar
335
NULL_COMPARISON_EXPRESSION_MISSING_EXPRESSION = The expression is missing from the null comparison expression.
336
# NullComparisonExpression - Semantic
337
NULL_COMPARISON_EXPRESSION_INVALID_TYPE = ''{0}'' cannot be resolved to an embeddable.
338
339
# NullIfExpression - Grammar
340
NULL_IF_EXPRESSION_INVALID_FIRST_EXPRESSION = The first argument is not a valid expression.
341
NULL_IF_EXPRESSION_INVALID_SECOND_EXPRESSION = The second argument is not a valid expression.
342
NULL_IF_EXPRESSION_MISSING_COMMA = The comma is missing from the NULLIF expression.
343
NULL_IF_EXPRESSION_MISSING_FIRST_EXPRESSION = The first argument is missing from the NULLIF expression.
344
NULL_IF_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the NULLIF expression.
345
NULL_IF_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the NULLIF expression.
346
NULL_IF_EXPRESSION_MISSING_SECOND_EXPRESSION = The second argument is missing from the NULLIF expression.
347
348
# NumericLiteral - Grammar
349
NUMERIC_LITERAL_INVALID = ''{0}'' is not a valid numeric value.
350
351
# ObjectByItem - Grammar
352
ORDER_BY_ITEM_INVALID_PATH = ''{0}'' is not a valid state field path expression.
353
ORDER_BY_ITEM_MISSING_STATE_FIELD_PATH_EXPRESSION = A state field path expression must be specified.
354
355
# ObjectExpression - Grammar
356
OBJECT_EXPRESSION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
357
OBJECT_EXPRESSION_MISSING_EXPRESSION = An identification variable must be provided for an OBJECT expression.
358
OBJECT_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the OBJECT expression.
359
OBJECT_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the OBJECT expression.
360
361
# OrderByClause - Grammar
362
ORDER_BY_CLAUSE_ORDER_BY_ITEM_ENDS_WITH_COMMA = The select expression cannot end with a comma.
363
ORDER_BY_CLAUSE_ORDER_BY_ITEM_IS_MISSING_COMMA = The ORDER BY clause has ''{0}'' and ''{1}'' that are not separated by a comma.
364
ORDER_BY_CLAUSE_ORDER_BY_ITEM_MISSING = The ordering item is missing from the ORDER BY clause.
365
366
# RangeVariableDeclaration - Grammar
367
RANGE_VARIABLE_DECLARATION_MISSING_ABSTRACT_SCHEMA_NAME = An abstract schema name must be specified.
368
RANGE_VARIABLE_DECLARATION_MISSING_IDENTIFICATION_VARIABLE = An identification variable must be provider for a range variable declaration.
369
370
# ResultVariable - Grammar
371
RESULT_VARIABLE_MISSING_SELECT_EXPRESSION = The select item is missing from the result variable declaration.
372
RESULT_VARIABLE_MISSING_RESULT_VARIABLE = The result variable is missing from the select item declaration.
373
374
# SelectStatement - Semantic
375
SELECT_STATEMENT_SELECT_CLAUSE_HAS_NON_AGGREGATE_FUNCTIONS = The select list can only consist of aggregate functions because there is no GROUP BY clause and the HAVING clause is used.
376
377
# SimpleSelectClause - Grammar
378
SIMPLE_SELECT_CLAUSE_NOT_SINGLE_EXPRESSION = Only one expression can be declared in a SELECT clause of a subquery.
379
380
# SizeExpression - Grammar
381
SIZE_EXPRESSION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
382
SIZE_EXPRESSION_MISSING_EXPRESSION = A collection-valued path expression must be provided for a SIZE expression.
383
SIZE_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the SIZE expression.
384
SIZE_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the SIZE expression.
385
386
# SqrtExpression - Grammar
387
SQRT_EXPRESSION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
388
SQRT_EXPRESSION_MISSING_EXPRESSION = An expression must be provided for a SQRT expression.
389
SQRT_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the SQRT expression.
390
SQRT_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the SQRT expression.
391
# SqrtExpression - Semantic
392
SQRT_EXPRESSION_WRONG_TYPE = The expression is not a numeric type.
393
394
# StateFieldPathExpression - Semantic
395
STATE_FIELD_PATH_EXPRESSION_ASSOCIATION_FIELD = The association field ''{0}'' cannot be used as a state field path.
396
STATE_FIELD_PATH_EXPRESSION_COLLECTION_TYPE = The state field path ''{0}'' cannot be resolved to a collection type.
397
STATE_FIELD_PATH_EXPRESSION_INVALID_ENUM_CONSTANT = ''{0}'' cannot be resolved to an Enum constant.
398
STATE_FIELD_PATH_EXPRESSION_NO_MAPPING = No mapping is associated with the state field path ''{0}''.
399
STATE_FIELD_PATH_EXPRESSION_NOT_RESOLVABLE = The state field path ''{0}'' cannot be resolved to a valid type.
400
401
# SubExpression - Grammar
402
SUB_EXPRESSION_MISSING_EXPRESSION = The encapsulated expression is missing.
403
SUB_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the sub-expression.
404
405
# SubstractionExpression - Semantic
406
SUBTRACTION_EXPRESSION_LEFT_EXPRESSION_WRONG_TYPE = The left side of the subtraction is not a valid arithmetic expression.
407
SUBTRACTION_EXPRESSION_RIGHT_EXPRESSION_WRONG_TYPE = The right side of the subtraction is not a valid arithmetic expression.
408
409
# SubstringExpression - Grammar
410
SUBSTRING_EXPRESSION_INVALID_FIRST_EXPRESSION = The first argument is not a valid expression.
411
SUBSTRING_EXPRESSION_INVALID_SECOND_EXPRESSION = The second argument is not a valid expression.
412
SUBSTRING_EXPRESSION_INVALID_THIRD_EXPRESSION = The third argument is not a valid expression.
413
SUBSTRING_EXPRESSION_MISSING_FIRST_COMMA = The first comma is missing from the SUBSTRING expression.
414
SUBSTRING_EXPRESSION_MISSING_FIRST_EXPRESSION = The first argument is missing from the SUBSTRING expression.
415
SUBSTRING_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the SUBSTRING expression.
416
SUBSTRING_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the SUBSTRING expression.
417
SUBSTRING_EXPRESSION_MISSING_SECOND_COMMA = The second comma is missing from the SUBSTRING expression.
418
SUBSTRING_EXPRESSION_MISSING_SECOND_EXPRESSION = The second argument is missing from the SUBSTRING expression.
419
SUBSTRING_EXPRESSION_MISSING_THIRD_EXPRESSION = The third argument is missing from the SUBSTRING expression.
420
# SubstringExpression - Semantic
421
SUBSTRING_EXPRESSION_FIRST_EXPRESSION_WRONG_TYPE = The first argument is not a String value.
422
SUBSTRING_EXPRESSION_SECOND_EXPRESSION_WRONG_TYPE = The first argument is not an integer value.
423
SUBSTRING_EXPRESSION_THIRD_EXPRESSION_WRONG_TYPE = The first argument is not an integer value.
424
425
# SumFunction - Grammar
426
SUM_FUNCTION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
427
SUM_FUNCTION_MISSING_EXPRESSION = The encapsulated expression must be provided for a SUM expression.
428
SUM_FUNCTION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the SUM expression.
429
SUM_FUNCTION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the SUM expression.
430
# SumFunction - Semantic
431
SUM_FUNCTION_WRONG_TYPE = The argument must be numeric.
432
433
# TrimExpression - Grammar
434
TRIM_EXPRESSION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
435
TRIM_EXPRESSION_INVALID_TRIM_CHARACTER = The trim character should be a single-character string literal or a character-valued input parameter (i.e., char or Character).
436
TRIM_EXPRESSION_MISSING_EXPRESSION = An expression must be provided for a TRIM expression.
437
TRIM_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the TRIM expression.
438
TRIM_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the TRIM expression.
439
TRIM_EXPRESSION_NOT_SINGLE_STRING_LITERAL = The trim character should be a single-character string literal.
440
441
# TypeExpression - Grammar
442
TYPE_EXPRESSION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
443
TYPE_EXPRESSION_MISSING_EXPRESSION = An identification variable or a path expression must be provided for a TYPE expression.
444
TYPE_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the TYPE expression.
445
TYPE_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the TYPE expression.
446
# TypeExpression - Semantic
447
448
# UpdateClause - Grammar
449
UPDATE_CLAUSE_MISSING_RANGE_VARIABLE_DECLARATION = The range variable declaration is missing from the UPDATE clause.
450
UPDATE_CLAUSE_MISSING_SET = The SET identifier is missing from the UPDATE clause.
451
UPDATE_CLAUSE_MISSING_UPDATE_ITEMS = At least one update item must be specified for an UPDATE clause.
452
UPDATE_CLAUSE_UPDATE_ITEM_ENDS_WITH_COMMA = The update item cannot end with a comma.
453
UPDATE_CLAUSE_UPDATE_ITEM_IS_MISSING_COMMA = The UPDATE clause has ''{0}'' and ''{1}'' that are not separated by a comma.
454
455
# UpdateItem - Grammar
456
UPDATE_ITEM_MISSING_EQUAL_SIGN = The equal sign must be specified.
457
UPDATE_ITEM_MISSING_NEW_VALUE = The new value must be specified.
458
UPDATE_ITEM_MISSING_STATE_FIELD_PATH_EXPRESSION = The state field path expression is missing.
459
# UpdateItem - Semantic
460
UPDATE_ITEM_NOT_ASSIGNABLE = Type mismatch: cannot convert from {0} to {1}.
461
UPDATE_ITEM_NOT_RESOLVABLE = The state field cannot be resolved.
462
463
# UpperExpression - Grammar
464
UPPER_EXPRESSION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
465
UPPER_EXPRESSION_MISSING_EXPRESSION = An expression must be provided for a UPPER expression.
466
UPPER_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the UPPER expression.
467
UPPER_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the UPPER expression.
468
# UpperExpression - Semantic
469
UPPER_EXPRESSION_WRONG_TYPE = The expression is not a String.
470
471
# ValueExpression - Grammar
472
VALUE_EXPRESSION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
473
VALUE_EXPRESSION_MISSING_EXPRESSION = An identification variable must be provided for a VALUE expression.
474
VALUE_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the VALUE expression.
475
VALUE_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the VALUE expression.
476
477
# WhenClause - Grammar
478
WHEN_CLAUSE_MISSING_THEN_EXPRESSION = A conditional expression must be provider for a WHEN clause.
479
WHEN_CLAUSE_MISSING_THEN_IDENTIFIER = The identifier THEN is missing from the WHEN clause.
480
WHEN_CLAUSE_MISSING_WHEN_EXPRESSION = A WHEN expression must be provided for a WHEN clause.
481
482
# WhereClause - Grammar
483
WHERE_CLAUSE_INVALID_CONDITIONAL_EXPRESSION = The expression is not a valid conditional expression.
484
WHERE_CLAUSE_MISSING_CONDITIONAL_EXPRESSION = The conditional expression is missing from the WHERE clause.
(-)src/org/eclipse/jpt/jpa/core/context/orm/OrmNamedQuery.java (-2 / +3 lines)
Lines 21-27 Link Here
21
 * stability. It is available at this early stage to solicit feedback from
21
 * stability. It is available at this early stage to solicit feedback from
22
 * pioneering adopters on the understanding that any code that uses this API
22
 * pioneering adopters on the understanding that any code that uses this API
23
 * will almost certainly be broken (repeatedly) as the API evolves.
23
 * will almost certainly be broken (repeatedly) as the API evolves.
24
 * 
24
 *
25
 * @version 2.1
25
 * @version 2.1
26
 * @since 2.0
26
 * @since 2.0
27
 */
27
 */
Lines 32-35 Link Here
32
32
33
	// required to resolve ambiguity
33
	// required to resolve ambiguity
34
	ListIterable<OrmQueryHint> getHints();
34
	ListIterable<OrmQueryHint> getHints();
35
}
35
36
}
(-)src/org/eclipse/jpt/jpa/core/context/orm/OrmQuery.java (-2 / +4 lines)
Lines 3-9 Link Here
3
 * This program and the accompanying materials are made available under the
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
6
 * 
6
 *
7
 * Contributors:
7
 * Contributors:
8
 *     Oracle - initial API and implementation
8
 *     Oracle - initial API and implementation
9
 ******************************************************************************/
9
 ******************************************************************************/
Lines 23-29 Link Here
23
 * stability. It is available at this early stage to solicit feedback from
23
 * stability. It is available at this early stage to solicit feedback from
24
 * pioneering adopters on the understanding that any code that uses this API
24
 * pioneering adopters on the understanding that any code that uses this API
25
 * will almost certainly be broken (repeatedly) as the API evolves.
25
 * will almost certainly be broken (repeatedly) as the API evolves.
26
 * 
26
 *
27
 * @version 2.1
27
 * @version 2.1
28
 * @since 2.0
28
 * @since 2.0
29
 */
29
 */
Lines 46-49 Link Here
46
	// ********** validation **********
46
	// ********** validation **********
47
47
48
	TextRange getNameTextRange();
48
	TextRange getNameTextRange();
49
50
	TextRange getQueryTextRange();
49
}
51
}
(-)src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmQuery.java (-8 / +26 lines)
Lines 10-17 Link Here
10
package org.eclipse.jpt.jpa.core.internal.context.orm;
10
package org.eclipse.jpt.jpa.core.internal.context.orm;
11
11
12
import java.util.Vector;
12
import java.util.Vector;
13
14
import org.eclipse.jpt.common.core.utility.TextRange;
13
import org.eclipse.jpt.common.core.utility.TextRange;
14
import org.eclipse.jpt.common.utility.internal.StringTools;
15
import org.eclipse.jpt.common.utility.internal.iterables.ListIterable;
15
import org.eclipse.jpt.common.utility.internal.iterables.ListIterable;
16
import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneIterable;
16
import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneIterable;
17
import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneListIterable;
17
import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneListIterable;
Lines 25-30 Link Here
25
import org.eclipse.jpt.jpa.core.resource.orm.OrmFactory;
25
import org.eclipse.jpt.jpa.core.resource.orm.OrmFactory;
26
import org.eclipse.jpt.jpa.core.resource.orm.XmlQuery;
26
import org.eclipse.jpt.jpa.core.resource.orm.XmlQuery;
27
import org.eclipse.jpt.jpa.core.resource.orm.XmlQueryHint;
27
import org.eclipse.jpt.jpa.core.resource.orm.XmlQueryHint;
28
import org.eclipse.persistence.jpa.jpql.ExpressionTools;
28
29
29
/**
30
/**
30
 * <code>orm.xml</code> query
31
 * <code>orm.xml</code> query
Lines 47-64 Link Here
47
		super(parent);
48
		super(parent);
48
		this.xmlQuery = xmlQuery;
49
		this.xmlQuery = xmlQuery;
49
		this.name = xmlQuery.getName();
50
		this.name = xmlQuery.getName();
50
		this.query = xmlQuery.getQuery();
51
		this.query = getUnescapeQuery();
51
		this.initializeHints();
52
		this.initializeHints();
52
	}
53
	}
53
54
54
55
	// ********** synchronize/update **********
55
	// ********** synchronize/update **********
56
56
57
	@Override
57
	@Override
58
	public void synchronizeWithResourceModel() { 
58
	public void synchronizeWithResourceModel() {
59
		super.synchronizeWithResourceModel();
59
		super.synchronizeWithResourceModel();
60
		this.setName_(this.xmlQuery.getName());
60
		this.setName_(this.xmlQuery.getName());
61
		this.setQuery_(this.xmlQuery.getQuery());
61
		this.setQuery_(this.getUnescapeQuery());
62
		this.syncHints();
62
		this.syncHints();
63
	}
63
	}
64
64
Lines 96-102 Link Here
96
96
97
	public void setQuery(String query) {
97
	public void setQuery(String query) {
98
		this.setQuery_(query);
98
		this.setQuery_(query);
99
		this.xmlQuery.setQuery(query);
99
		this.xmlQuery.setQuery(this.convertToEscapeQuery(query));
100
	}
100
	}
101
101
102
	protected void setQuery_(String query) {
102
	protected void setQuery_(String query) {
Lines 105-110 Link Here
105
		this.firePropertyChanged(QUERY_PROPERTY, old, query);
105
		this.firePropertyChanged(QUERY_PROPERTY, old, query);
106
	}
106
	}
107
107
108
	protected String getUnescapeQuery() {
109
		String query = this.xmlQuery.getQuery();
110
		if (StringTools.stringIsNotEmpty(query)) {
111
			query = ExpressionTools.unescape(query, new int[1]);
112
		}
113
		return query;
114
	}
115
116
	protected String convertToEscapeQuery(String query) {
117
		if (StringTools.stringIsNotEmpty(query)) {
118
			query = ExpressionTools.escape(query, new int[1]);
119
		}
120
		return query;
121
	}
122
108
123
109
	// ********** hints **********
124
	// ********** hints **********
110
125
Lines 231-239 Link Here
231
		return this.xmlQuery.getNameTextRange();
246
		return this.xmlQuery.getNameTextRange();
232
	}
247
	}
233
248
249
	public TextRange getQueryTextRange() {
250
		return this.xmlQuery.getQueryTextRange();
251
	}
252
234
	@Override
253
	@Override
235
	public void toString(StringBuilder sb) {
254
	public void toString(StringBuilder sb) {
236
		sb.append(this.name);
255
		sb.append(this.name);
237
	}
256
	}
238
257
}
239
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaNamedQuery.java (-3 / +22 lines)
Lines 1-18 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2010 Oracle. All rights reserved.
2
 * Copyright (c) 2007, 2011 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
6
 * 
6
 *
7
 * Contributors:
7
 * Contributors:
8
 *     Oracle - initial API and implementation
8
 *     Oracle - initial API and implementation
9
 ******************************************************************************/
9
 ******************************************************************************/
10
package org.eclipse.jpt.jpa.core.internal.jpa1.context.java;
10
package org.eclipse.jpt.jpa.core.internal.jpa1.context.java;
11
11
12
import java.util.List;
13
import org.eclipse.jdt.core.dom.CompilationUnit;
12
import org.eclipse.jpt.jpa.core.context.java.JavaJpaContextNode;
14
import org.eclipse.jpt.jpa.core.context.java.JavaJpaContextNode;
13
import org.eclipse.jpt.jpa.core.context.java.JavaNamedQuery;
15
import org.eclipse.jpt.jpa.core.context.java.JavaNamedQuery;
14
import org.eclipse.jpt.jpa.core.internal.context.java.AbstractJavaQuery;
16
import org.eclipse.jpt.jpa.core.internal.context.java.AbstractJavaQuery;
17
import org.eclipse.jpt.jpa.core.internal.jpql.JpaJpqlQueryHelper;
15
import org.eclipse.jpt.jpa.core.resource.java.NamedQueryAnnotation;
18
import org.eclipse.jpt.jpa.core.resource.java.NamedQueryAnnotation;
19
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
20
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
16
21
17
/**
22
/**
18
 * Java named query
23
 * Java named query
Lines 24-27 Link Here
24
	public GenericJavaNamedQuery(JavaJpaContextNode parent, NamedQueryAnnotation queryAnnotation) {
29
	public GenericJavaNamedQuery(JavaJpaContextNode parent, NamedQueryAnnotation queryAnnotation) {
25
		super(parent, queryAnnotation);
30
		super(parent, queryAnnotation);
26
	}
31
	}
27
}
32
33
34
	// ********** validation **********
35
36
	/**
37
	 * {@inheritDoc}
38
	 */
39
	@Override
40
	public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) {
41
		super.validate(messages, reporter, astRoot);
42
43
		JpaJpqlQueryHelper helper = new JpaJpqlQueryHelper();
44
		helper.validate(this, this.getQuery(), this.getQueryAnnotation().getQueryTextRange(astRoot), 1, messages);
45
	}
46
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaQueryContainer.java (-2 / +5 lines)
Lines 308-317 Link Here
308
	@Override
308
	@Override
309
	public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) {
309
	public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) {
310
		super.validate(messages, reporter, astRoot);
310
		super.validate(messages, reporter, astRoot);
311
		this.validateQueries(messages, astRoot);
311
		this.validateQueries(messages, reporter, astRoot);
312
	}
312
	}
313
313
314
	protected void validateQueries(List<IMessage> messages, CompilationUnit astRoot) {
314
	protected void validateQueries(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) {
315
		for (Iterator<JavaQuery> localQueries = this.queries(); localQueries.hasNext(); ) {
315
		for (Iterator<JavaQuery> localQueries = this.queries(); localQueries.hasNext(); ) {
316
			JavaQuery localQuery = localQueries.next();
316
			JavaQuery localQuery = localQueries.next();
317
			String name = localQuery.getName();
317
			String name = localQuery.getName();
Lines 354-359 Link Here
354
						)
354
						)
355
				);
355
				);
356
			}
356
			}
357
			else {
358
				localQuery.validate(messages, reporter, astRoot);
359
			}
357
		}
360
		}
358
	}
361
	}
359
362
(-)src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmNamedQuery.java (-3 / +24 lines)
Lines 1-18 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2010 Oracle. All rights reserved.
2
 * Copyright (c) 2007, 2011 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
6
 * 
6
 *
7
 * Contributors:
7
 * Contributors:
8
 *     Oracle - initial API and implementation
8
 *     Oracle - initial API and implementation
9
 ******************************************************************************/
9
 ******************************************************************************/
10
package org.eclipse.jpt.jpa.core.internal.jpa1.context.orm;
10
package org.eclipse.jpt.jpa.core.internal.jpa1.context.orm;
11
11
12
import java.util.List;
12
import org.eclipse.jpt.jpa.core.context.XmlContextNode;
13
import org.eclipse.jpt.jpa.core.context.XmlContextNode;
13
import org.eclipse.jpt.jpa.core.context.orm.OrmNamedQuery;
14
import org.eclipse.jpt.jpa.core.context.orm.OrmNamedQuery;
14
import org.eclipse.jpt.jpa.core.internal.context.orm.AbstractOrmQuery;
15
import org.eclipse.jpt.jpa.core.internal.context.orm.AbstractOrmQuery;
16
import org.eclipse.jpt.jpa.core.internal.jpql.JpaJpqlQueryHelper;
15
import org.eclipse.jpt.jpa.core.resource.orm.XmlNamedQuery;
17
import org.eclipse.jpt.jpa.core.resource.orm.XmlNamedQuery;
18
import org.eclipse.persistence.jpa.jpql.ExpressionTools;
19
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
20
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
16
21
17
/**
22
/**
18
 * <code>orm.xml</code> named query
23
 * <code>orm.xml</code> named query
Lines 24-27 Link Here
24
	public GenericOrmNamedQuery(XmlContextNode parent, XmlNamedQuery resourceNamedQuery) {
29
	public GenericOrmNamedQuery(XmlContextNode parent, XmlNamedQuery resourceNamedQuery) {
25
		super(parent, resourceNamedQuery);
30
		super(parent, resourceNamedQuery);
26
	}
31
	}
27
}
32
33
	// ********** validation **********
34
35
	/**
36
	 * {@inheritDoc}
37
	 */
38
	@Override
39
	public void validate(List<IMessage> messages, IReporter reporter) {
40
		super.validate(messages, reporter);
41
42
		// Convert the literal escape characters into actual escape characters
43
		String jpqlQuery = ExpressionTools.unescape(this.getQuery(), new int[1]);
44
45
		JpaJpqlQueryHelper helper = new JpaJpqlQueryHelper();
46
		helper.validate(this, jpqlQuery, this.getQueryTextRange(), 0, messages);
47
	}
48
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmQueryContainer.java (-3 / +5 lines)
Lines 14-20 Link Here
14
import java.util.List;
14
import java.util.List;
15
import java.util.ListIterator;
15
import java.util.ListIterator;
16
import java.util.Vector;
16
import java.util.Vector;
17
18
import org.eclipse.jpt.common.core.utility.TextRange;
17
import org.eclipse.jpt.common.core.utility.TextRange;
19
import org.eclipse.jpt.common.utility.internal.StringTools;
18
import org.eclipse.jpt.common.utility.internal.StringTools;
20
import org.eclipse.jpt.common.utility.internal.iterables.CompositeIterable;
19
import org.eclipse.jpt.common.utility.internal.iterables.CompositeIterable;
Lines 300-309 Link Here
300
	@Override
299
	@Override
301
	public void validate(List<IMessage> messages, IReporter reporter) {
300
	public void validate(List<IMessage> messages, IReporter reporter) {
302
		super.validate(messages, reporter);
301
		super.validate(messages, reporter);
303
		this.validateQueries(messages);
302
		this.validateQueries(messages, reporter);
304
	}
303
	}
305
304
306
	protected void validateQueries(List<IMessage> messages) {
305
	protected void validateQueries(List<IMessage> messages, IReporter reporter) {
307
		for (OrmQuery localQuery : this.getQueries()) {
306
		for (OrmQuery localQuery : this.getQueries()) {
308
			String name = localQuery.getName();
307
			String name = localQuery.getName();
309
			if (StringTools.stringIsEmpty(name)){
308
			if (StringTools.stringIsEmpty(name)){
Lines 345-350 Link Here
345
						)
344
						)
346
				);
345
				);
347
			}
346
			}
347
			else {
348
				localQuery.validate(messages, reporter);
349
			}
348
		}
350
		}
349
	}
351
	}
350
352
(-)src/org/eclipse/jpt/jpa/core/internal/jpa2/context/java/GenericJavaNamedQuery2_0.java (-2 / +20 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
* Copyright (c) 2009, 2010 Oracle. All rights reserved.
2
* Copyright (c) 2009, 2011 Oracle. All rights reserved.
3
* This program and the accompanying materials are made available under the
3
* This program and the accompanying materials are made available under the
4
* terms of the Eclipse Public License v1.0, which accompanies this distribution
4
* terms of the Eclipse Public License v1.0, which accompanies this distribution
5
* and is available at http://www.eclipse.org/legal/epl-v10.html.
5
* and is available at http://www.eclipse.org/legal/epl-v10.html.
Lines 9-19 Link Here
9
*******************************************************************************/
9
*******************************************************************************/
10
package org.eclipse.jpt.jpa.core.internal.jpa2.context.java;
10
package org.eclipse.jpt.jpa.core.internal.jpa2.context.java;
11
11
12
import java.util.List;
13
import org.eclipse.jdt.core.dom.CompilationUnit;
12
import org.eclipse.jpt.jpa.core.context.java.JavaJpaContextNode;
14
import org.eclipse.jpt.jpa.core.context.java.JavaJpaContextNode;
13
import org.eclipse.jpt.jpa.core.internal.context.java.AbstractJavaQuery;
15
import org.eclipse.jpt.jpa.core.internal.context.java.AbstractJavaQuery;
16
import org.eclipse.jpt.jpa.core.internal.jpql.JpaJpqlQueryHelper;
14
import org.eclipse.jpt.jpa.core.jpa2.context.LockModeType2_0;
17
import org.eclipse.jpt.jpa.core.jpa2.context.LockModeType2_0;
15
import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaNamedQuery2_0;
18
import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaNamedQuery2_0;
16
import org.eclipse.jpt.jpa.core.jpa2.resource.java.NamedQuery2_0Annotation;
19
import org.eclipse.jpt.jpa.core.jpa2.resource.java.NamedQuery2_0Annotation;
20
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
21
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
17
22
18
/**
23
/**
19
 * JPA 2.0
24
 * JPA 2.0
Lines 87-90 Link Here
87
		return LockModeType2_0.NONE;
92
		return LockModeType2_0.NONE;
88
	}
93
	}
89
94
90
}
95
96
	// ********** validation **********
97
98
	/**
99
	 * {@inheritDoc}
100
	 */
101
	@Override
102
	public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) {
103
		super.validate(messages, reporter, astRoot);
104
105
		JpaJpqlQueryHelper helper = new JpaJpqlQueryHelper();
106
		helper.validate(this, this.getQuery(), this.getQueryAnnotation().getQueryTextRange(astRoot), 1, messages);
107
	}
108
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpa2/context/orm/GenericOrmNamedQuery2_0.java (-3 / +23 lines)
Lines 1-19 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2010 Oracle. All rights reserved.
2
 * Copyright (c) 2007, 2011 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
6
 * 
6
 *
7
 * Contributors:
7
 * Contributors:
8
 *     Oracle - initial API and implementation
8
 *     Oracle - initial API and implementation
9
 ******************************************************************************/
9
 ******************************************************************************/
10
package org.eclipse.jpt.jpa.core.internal.jpa2.context.orm;
10
package org.eclipse.jpt.jpa.core.internal.jpa2.context.orm;
11
11
12
import java.util.List;
12
import org.eclipse.jpt.jpa.core.context.XmlContextNode;
13
import org.eclipse.jpt.jpa.core.context.XmlContextNode;
13
import org.eclipse.jpt.jpa.core.internal.context.orm.AbstractOrmQuery;
14
import org.eclipse.jpt.jpa.core.internal.context.orm.AbstractOrmQuery;
15
import org.eclipse.jpt.jpa.core.internal.jpql.JpaJpqlQueryHelper;
14
import org.eclipse.jpt.jpa.core.jpa2.context.LockModeType2_0;
16
import org.eclipse.jpt.jpa.core.jpa2.context.LockModeType2_0;
15
import org.eclipse.jpt.jpa.core.jpa2.context.orm.OrmNamedQuery2_0;
17
import org.eclipse.jpt.jpa.core.jpa2.context.orm.OrmNamedQuery2_0;
16
import org.eclipse.jpt.jpa.core.resource.orm.XmlNamedQuery;
18
import org.eclipse.jpt.jpa.core.resource.orm.XmlNamedQuery;
19
import org.eclipse.persistence.jpa.jpql.ExpressionTools;
20
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
21
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
17
22
18
/**
23
/**
19
 * JPA 2.0
24
 * JPA 2.0
Lines 87-90 Link Here
87
		return LockModeType2_0.NONE;
92
		return LockModeType2_0.NONE;
88
	}
93
	}
89
94
90
}
95
	// ********** validation **********
96
97
	/**
98
	 * {@inheritDoc}
99
	 */
100
	@Override
101
	public void validate(List<IMessage> messages, IReporter reporter) {
102
		super.validate(messages, reporter);
103
104
		// Convert the literal escape characters into actual escape characters
105
		String jpqlQuery = ExpressionTools.unescape(this.getQuery(), new int[1]);
106
107
		JpaJpqlQueryHelper helper = new JpaJpqlQueryHelper();
108
		helper.validate(this, jpqlQuery, this.getQueryTextRange(), 0, messages);
109
	}
110
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpql/ClassConstructor.java (+143 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
5
 * which accompanies this distribution.
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.core.internal.jpql;
15
16
import org.eclipse.jdt.core.BindingKey;
17
import org.eclipse.jdt.core.IMethod;
18
import org.eclipse.jdt.core.Signature;
19
import org.eclipse.persistence.jpa.jpql.spi.IConstructor;
20
import org.eclipse.persistence.jpa.jpql.spi.IType;
21
import org.eclipse.persistence.jpa.jpql.spi.ITypeDeclaration;
22
import org.eclipse.persistence.jpa.jpql.spi.ITypeRepository;
23
24
/**
25
 * The concrete implementation of {@link IConstructor} that is wrapping the {@link IMethod}
26
 * representation of a Java constructor (either coming from a Java compiled file or a Java source
27
 * file).
28
 *
29
 * @version 3.0
30
 * @since 3.0
31
 * @author Pascal Filion
32
 */
33
final class ClassConstructor implements IConstructor {
34
35
	/**
36
	 * The information of the constructor.
37
	 */
38
	private IMethod method;
39
40
	/**
41
	 * The declaring type of this constructor.
42
	 */
43
	private JpaType type;
44
45
	/**
46
	 * The cached {@link ITypeDeclaration ITypeDeclarations} representing each of the constructor's
47
	 * parameter types.
48
	 */
49
	private ITypeDeclaration[] typeDeclarations;
50
51
	/**
52
	 * Creates a new <code>ClassConstructor</code>.
53
	 *
54
	 * @param type The declaring type of this constructor
55
	 * @param methodInfo The information of the constructor
56
	 */
57
	ClassConstructor(JpaType type, IMethod method) {
58
		super();
59
		this.type   = type;
60
		this.method = method;
61
	}
62
63
	private ITypeDeclaration[] buildParameterTypes() {
64
65
		BindingKey bindingKey = new BindingKey(method.getKey());
66
		String signature = bindingKey.toSignature();
67
68
		int count = Signature.getParameterCount(signature);
69
		ITypeDeclaration[] typeDeclarations = new ITypeDeclaration[count];
70
		int index = 0;
71
72
		for (String parameterType : Signature.getParameterTypes(signature)) {
73
74
			// 1. Retrieve the parameter type (without the type parameters)
75
			String parameterTypeName = Signature.getTypeErasure(parameterType);
76
77
			// 3. Convert the type signature to a dot-based name
78
			parameterTypeName = Signature.toString(parameterTypeName);
79
80
			// 4. Create the ITypeDeclaration
81
			typeDeclarations[index++] = new JpaTypeDeclaration(
82
				getTypeRepository().getType(parameterTypeName),
83
				buildTypeParameters(parameterType),
84
				Signature.getArrayCount(parameterType)
85
			);
86
		}
87
88
		return typeDeclarations;
89
	}
90
91
	private ITypeDeclaration[] buildTypeParameters(String signature) {
92
93
		String[] typeParameters = Signature.getTypeArguments(signature);
94
		ITypeDeclaration[] generics = new ITypeDeclaration[typeParameters.length];
95
96
		for (int index = 0; index < typeParameters.length; index++) {
97
			String typeParameter = typeParameters[index];
98
99
			// 1. Retrieve the parameter type (without the wild cards)
100
			switch (Signature.getTypeSignatureKind(typeParameter)) {
101
				case Signature.WILDCARD_TYPE_SIGNATURE: {
102
					typeParameter = typeParameter.substring(1);
103
				}
104
			}
105
106
			if (typeParameter.length() == 0) {
107
				generics[index] = getTypeRepository().getTypeHelper().objectTypeDeclaration();
108
			}
109
			else {
110
				String typeParameterName = Signature.getTypeErasure(typeParameter);
111
112
				// 3. Convert the type signature to a dot-based name
113
				typeParameterName = Signature.toString(typeParameterName);
114
115
				// 3. Retrieve the IType for the type parameter
116
				IType genericType = getTypeRepository().getType(typeParameterName);
117
118
				if (genericType.isResolvable()) {
119
					generics[index] = genericType.getTypeDeclaration();
120
				}
121
				else {
122
					generics[index] = getTypeRepository().getTypeHelper().objectTypeDeclaration();
123
				}
124
			}
125
		}
126
127
		return generics;
128
	}
129
130
	/**
131
	 * {@inheritDoc}
132
	 */
133
	public ITypeDeclaration[] getParameterTypes() {
134
		if (typeDeclarations == null) {
135
			typeDeclarations = buildParameterTypes();
136
		}
137
		return typeDeclarations;
138
	}
139
140
	private ITypeRepository getTypeRepository() {
141
		return type.getTypeRepository();
142
	}
143
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpql/IJpaType.java (+38 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
5
 * which accompanies this distribution.
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.core.internal.jpql;
15
16
import org.eclipse.persistence.jpa.jpql.spi.IType;
17
18
/**
19
 * An internal interface used by all 3 implementations of {@link IType}.
20
 *
21
 * @see JavaType
22
 * @see JpaType
23
 * @see SimpleType
24
 *
25
 * @version 3.0
26
 * @since 3.0
27
 * @author Pascal Filion
28
 */
29
interface IJpaType extends IType {
30
31
	/**
32
	 * Manually sets the declaration of this {@link IType}, which gives the information about type
33
	 * parameters, dimensionality, etc.
34
	 *
35
	 * @param typeDeclaration The external form of the type declaration
36
	 */
37
	void setTypeDeclaration(JpaTypeDeclaration typeDeclaration);
38
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpql/JavaConstructor.java (+99 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
5
 * which accompanies this distribution.
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.core.internal.jpql;
15
16
import java.lang.reflect.Constructor;
17
import java.lang.reflect.Type;
18
import org.eclipse.persistence.jpa.jpql.spi.IConstructor;
19
import org.eclipse.persistence.jpa.jpql.spi.IType;
20
import org.eclipse.persistence.jpa.jpql.spi.ITypeDeclaration;
21
import org.eclipse.persistence.jpa.jpql.spi.ITypeRepository;
22
23
/**
24
 * The concrete implementation of {@link IConstructor} that is wrapping a Java constructor.
25
 *
26
 * @version 2.3
27
 * @since 2.3
28
 * @author Pascal Filion
29
 */
30
final class JavaConstructor implements IConstructor {
31
32
	/**
33
	 * The actual Java constructor.
34
	 */
35
	private Constructor<?> constructor;
36
37
	/**
38
	 * The cached {@link ITypeDeclaration parameter types}.
39
	 */
40
	private ITypeDeclaration[] parameterTypes;
41
42
	/**
43
	 * The declaring type of this constructor.
44
	 */
45
	private JavaType type;
46
47
	/**
48
	 * Creates a new <code>JavaConstructor</code>.
49
	 *
50
	 * @param type The declaring type of this constructor
51
	 * @param constructor The actual Java constructor
52
	 */
53
	JavaConstructor(JavaType type, Constructor<?> constructor) {
54
		super();
55
		this.type = type;
56
		this.constructor = constructor;
57
	}
58
59
	private ITypeDeclaration[] buildParameterTypes() {
60
61
		Class<?>[] types = constructor.getParameterTypes();
62
		Type[] genericTypes = constructor.getGenericParameterTypes();
63
		ITypeDeclaration[] typeDeclarations = new ITypeDeclaration[types.length];
64
65
		for (int index = 0, count = types.length; index < count; index++) {
66
			typeDeclarations[index] = buildTypeDeclaration(types[index], genericTypes[index]);
67
		}
68
69
		return typeDeclarations;
70
	}
71
72
	private ITypeDeclaration buildTypeDeclaration(Class<?> javaType, Type genericType) {
73
		ITypeRepository typeRepository = getTypeRepository();
74
		IType type = typeRepository.getType(javaType);
75
		return new JavaTypeDeclaration(typeRepository, type, genericType, javaType.isArray());
76
	}
77
78
	/**
79
	 * {@inheritDoc}
80
	 */
81
	public ITypeDeclaration[] getParameterTypes() {
82
		if (parameterTypes == null) {
83
			parameterTypes = buildParameterTypes();
84
		}
85
		return parameterTypes;
86
	}
87
88
	private ITypeRepository getTypeRepository() {
89
		return type.getTypeRepository();
90
	}
91
92
	/**
93
	 * {@inheritDoc}
94
	 */
95
	@Override
96
	public String toString() {
97
		return constructor.toGenericString();
98
	}
99
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpql/JavaType.java (+246 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
5
 * which accompanies this distribution.
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.core.internal.jpql;
15
16
import java.lang.annotation.Annotation;
17
import java.lang.reflect.Constructor;
18
import java.util.ArrayList;
19
import java.util.Collection;
20
import java.util.Collections;
21
import org.eclipse.persistence.jpa.jpql.ExpressionTools;
22
import org.eclipse.persistence.jpa.jpql.spi.IConstructor;
23
import org.eclipse.persistence.jpa.jpql.spi.IType;
24
import org.eclipse.persistence.jpa.jpql.spi.ITypeDeclaration;
25
import org.eclipse.persistence.jpa.jpql.spi.ITypeRepository;
26
27
/**
28
 * The concrete implementation of {@link IType} that is wrapping a Java type.
29
 *
30
 * @version 2.3
31
 * @since 2.3
32
 * @author Pascal Filion
33
 */
34
final class JavaType implements IJpaType {
35
36
	/**
37
	 * The cached {@link IConstructor IConstructors}.
38
	 */
39
	private Collection<IConstructor> constructors;
40
41
	/**
42
	 * The list of names for the {@link Enum}'s constants otherwise an empty array.
43
	 */
44
	private String[] enumConstants;
45
46
	/**
47
	 * The actual Java type.
48
	 */
49
	private Class<?> type;
50
51
	/**
52
	 * The cached {@link ITypeDeclaration} for this {@link IType}.
53
	 */
54
	private ITypeDeclaration typeDeclaration;
55
56
	/**
57
	 * The fully qualified name of the Java type.
58
	 */
59
	private String typeName;
60
61
	/**
62
	 * The external form of a type repository.
63
	 */
64
	private ITypeRepository typeRepository;
65
66
	/**
67
	 * Creates a new <code>JavaType</code>.
68
	 *
69
	 * @param typeRepository The external form of a type repository
70
	 * @param type The actual Java type wrapped by this class
71
	 */
72
	JavaType(ITypeRepository typeRepository, Class<?> type) {
73
		super();
74
		this.type           = type;
75
		this.typeName       = type.getName();
76
		this.typeRepository = typeRepository;
77
	}
78
79
	private IConstructor buildConstructor(Constructor<?> constructor) {
80
		return new JavaConstructor(this, constructor);
81
	}
82
83
	private Collection<IConstructor> buildConstructors() {
84
85
		Constructor<?>[] javaConstructors = type.getDeclaredConstructors();
86
		Collection<IConstructor> constructors = new ArrayList<IConstructor>(javaConstructors.length);
87
88
		for (Constructor<?> javaConstructor : javaConstructors) {
89
			constructors.add(buildConstructor(javaConstructor));
90
		}
91
92
		return constructors;
93
	}
94
95
	private String[] buildEnumConstants() {
96
97
		if (!type.isEnum()) {
98
			return ExpressionTools.EMPTY_STRING_ARRAY;
99
		}
100
101
		Object[] enumConstants = type.getEnumConstants();
102
		String[] names = new String[enumConstants.length];
103
104
		for (int index = enumConstants.length; --index >= 0; ) {
105
			names[index] = ((Enum<?>) enumConstants[index]).name();
106
		}
107
108
		return names;
109
	}
110
111
	/**
112
	 * {@inheritDoc}
113
	 */
114
	public Iterable<IConstructor> constructors() {
115
		if (constructors == null) {
116
			constructors = buildConstructors();
117
		}
118
		return Collections.unmodifiableCollection(constructors);
119
	}
120
121
	/**
122
	 * {@inheritDoc}
123
	 */
124
	public boolean equals(IType type) {
125
		return (this == type) ? true : typeName.equals(type.getName());
126
	}
127
128
	/**
129
	 * {@inheritDoc}
130
	 */
131
	@Override
132
	public boolean equals(Object object) {
133
		return (this == object) || equals((IType) object);
134
	}
135
136
	/**
137
	 * {@inheritDoc}
138
	 */
139
	public String[] getEnumConstants() {
140
		if (enumConstants == null) {
141
			enumConstants = buildEnumConstants();
142
		}
143
		return enumConstants;
144
	}
145
146
	/**
147
	 * {@inheritDoc}
148
	 */
149
	public String getName() {
150
		return typeName;
151
	}
152
153
	/**
154
	 * Returns the encapsulated {@link Class}, which is the actual type.
155
	 *
156
	 * @return The actual Java type, if <code>null</code> is returned; then the class could not be resolved
157
	 */
158
	Class<?> getType() {
159
		return type;
160
	}
161
162
	/**
163
	 * {@inheritDoc}
164
	 */
165
	public ITypeDeclaration getTypeDeclaration() {
166
		if (typeDeclaration == null) {
167
			typeDeclaration = new JavaTypeDeclaration(typeRepository, this, null, (type != null) ? type.isArray() : false);
168
		}
169
		return typeDeclaration;
170
	}
171
172
	/**
173
	 * Returns the type repository for the application.
174
	 *
175
	 * @return The repository of {@link IType ITypes}
176
	 */
177
	ITypeRepository getTypeRepository() {
178
		return typeRepository;
179
	}
180
181
	/**
182
	 * {@inheritDoc}
183
	 */
184
	public boolean hasAnnotation(Class<? extends Annotation> annotationType) {
185
		return type.isAnnotationPresent(annotationType);
186
	}
187
188
	/**
189
	 * {@inheritDoc}
190
	 */
191
	@Override
192
	public int hashCode() {
193
		return typeName.hashCode();
194
	}
195
196
	/**
197
	 * {@inheritDoc}
198
	 */
199
	public boolean isAssignableTo(IType type) {
200
201
		if (this == type) {
202
			return true;
203
		}
204
205
		// TODO
206
		if (type instanceof JavaType) {
207
			Class<?> otherType = ((JavaType) type).type;
208
			return otherType.isAssignableFrom(this.type);
209
		}
210
		else if (type instanceof JpaType) {
211
			// TODO
212
			return false;
213
		}
214
215
		return false;
216
	}
217
218
	/**
219
	 * {@inheritDoc}
220
	 */
221
	public boolean isEnum() {
222
		return (type != null) && type.isEnum();
223
	}
224
225
	/**
226
	 * {@inheritDoc}
227
	 */
228
	public boolean isResolvable() {
229
		return true;
230
	}
231
232
	/**
233
	 * {@inheritDoc}
234
	 */
235
	public void setTypeDeclaration(JpaTypeDeclaration typeDeclaration) {
236
		this.typeDeclaration = typeDeclaration;
237
	}
238
239
	/**
240
	 * {@inheritDoc}
241
	 */
242
	@Override
243
	public String toString() {
244
		return typeName;
245
	}
246
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpql/JavaTypeDeclaration.java (+271 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
5
 * which accompanies this distribution.
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.core.internal.jpql;
15
16
import java.lang.reflect.GenericArrayType;
17
import java.lang.reflect.ParameterizedType;
18
import java.lang.reflect.Type;
19
import java.lang.reflect.TypeVariable;
20
import java.lang.reflect.WildcardType;
21
import java.util.ArrayList;
22
import java.util.List;
23
import org.eclipse.persistence.jpa.jpql.spi.IType;
24
import org.eclipse.persistence.jpa.jpql.spi.ITypeDeclaration;
25
import org.eclipse.persistence.jpa.jpql.spi.ITypeRepository;
26
27
/**
28
 * The concrete implementation of {@link ITypeDeclaration} that is wrapping the representation
29
 * of the declaration description of a type.
30
 *
31
 * @see IMapping
32
 * @see IType
33
 *
34
 * @version 2.3
35
 * @since 2.3
36
 * @author Pascal Filion
37
 */
38
@SuppressWarnings("nls")
39
final class JavaTypeDeclaration implements ITypeDeclaration {
40
41
	/**
42
	 * Determines whether the type declaration represents an array.
43
	 */
44
	private boolean array;
45
46
	/**
47
	 * The actual type that contains the generics, if any is present.
48
	 */
49
	private Object genericType;
50
51
	/**
52
	 * The cached {@link ITypeDeclaration ITypeDeclarations} representing the generics of the {@link
53
	 * Type}.
54
	 */
55
	private ITypeDeclaration[] genericTypes;
56
57
	/**
58
	 * The external form of the Java type.
59
	 */
60
	private final IType type;
61
62
	/**
63
	 * The repository of {@link IType ITypes}.
64
	 */
65
	private ITypeRepository typeRepository;
66
67
	/**
68
	 * Creates a new <code>JavaTypeDeclaration</code>.
69
	 *
70
	 * @param typeRepository The repository of {@link IType ITypes}
71
	 * @param type The external form of the Java type
72
	 * @param genericType The actual type that contains the generics, if any is present
73
	 * @param array Determines whether the type declaration represents an array
74
	 */
75
	JavaTypeDeclaration(ITypeRepository typeRepository,
76
	                    IType type,
77
	                    Object genericType,
78
	                    boolean array) {
79
80
		super();
81
		this.type           = type;
82
		this.array          = array;
83
		this.genericType    = genericType;
84
		this.typeRepository = typeRepository;
85
	}
86
87
	private String buildArrayTypeName(String arrayTypeName) {
88
89
		StringBuilder sb = new StringBuilder();
90
		int index = arrayTypeName.indexOf('[');
91
		int dimensionality = (arrayTypeName.length() - index) / 2;
92
		String typeName = arrayTypeName.substring(0, index);
93
94
		while (--dimensionality >= 0) {
95
			sb.append("[");
96
		}
97
98
		String elementType = elementType(typeName);
99
100
		sb.append(elementType);
101
		sb.append(typeName);
102
103
		if (elementType.equals("L")) {
104
			sb.append(";");
105
		}
106
107
		return sb.toString();
108
	}
109
110
	private ITypeDeclaration[] buildParameterTypes() {
111
112
		List<ITypeDeclaration> parameterTypes = new ArrayList<ITypeDeclaration>();
113
114
		// Example: Class<T>
115
		if (genericType instanceof ParameterizedType) {
116
			ParameterizedType parameterizedType = (ParameterizedType) genericType;
117
			for (Type type : parameterizedType.getActualTypeArguments()) {
118
				ITypeDeclaration typeParameter = buildTypeDeclaration(type);
119
				parameterTypes.add(typeParameter);
120
			}
121
		}
122
		// T[]
123
		else if (genericType instanceof GenericArrayType) {
124
			GenericArrayType genericArrayType = (GenericArrayType) genericType;
125
			parameterTypes.add(buildTypeDeclaration(genericArrayType.getGenericComponentType()));
126
		}
127
		// Example: Class
128
		else if (genericType.getClass() == Class.class) {
129
			ITypeDeclaration typeParameter = buildTypeDeclaration((Class<?>) genericType);
130
			parameterTypes.add(typeParameter);
131
		}
132
		// Example: <K, V>
133
		else if (genericType.getClass() == Class[].class) {
134
			for (Class<?> javaType : ((Class<?>[]) genericType)) {
135
				ITypeDeclaration typeParameter = buildTypeDeclaration(javaType);
136
				parameterTypes.add(typeParameter);
137
			}
138
		}
139
		// Example: <K, V>
140
		else if (genericType.getClass() == IType[].class) {
141
			for (IType type : ((IType[]) genericType)) {
142
				ITypeDeclaration typeParameter = new JavaTypeDeclaration(typeRepository, type, null, false);
143
				parameterTypes.add(typeParameter);
144
			}
145
		}
146
147
		return parameterTypes.toArray(new ITypeDeclaration[parameterTypes.size()]);
148
	}
149
150
	private JavaTypeDeclaration buildTypeDeclaration(Class<?> javaType) {
151
		return new JavaTypeDeclaration(
152
			typeRepository,
153
			getType(javaType),
154
			null,
155
			javaType.isArray()
156
		);
157
	}
158
159
	private JavaTypeDeclaration buildTypeDeclaration(Object genericType) {
160
161
		// <T1, ..., Tn>
162
		if (genericType instanceof ParameterizedType) {
163
			ParameterizedType parameterizedType = (ParameterizedType) genericType;
164
			return buildTypeDeclaration(parameterizedType.getRawType());
165
		}
166
167
		// <T>
168
		if (genericType instanceof TypeVariable) {
169
			TypeVariable<?> typeVariable = (TypeVariable<?>) genericType;
170
			for (Type type : typeVariable.getBounds()) {
171
				return buildTypeDeclaration(type);
172
			}
173
			return buildTypeDeclaration(Object.class);
174
		}
175
176
		// ?
177
		if (genericType instanceof WildcardType) {
178
			WildcardType wildcardType = (WildcardType) genericType;
179
			for (Type type : wildcardType.getUpperBounds()) {
180
				return buildTypeDeclaration(type);
181
			}
182
			return buildTypeDeclaration(Object.class);
183
		}
184
185
		// T[]
186
		if (genericType instanceof GenericArrayType) {
187
			GenericArrayType genericArrayType = (GenericArrayType) genericType;
188
			String arrayTypeName = buildArrayTypeName(genericArrayType.toString());
189
			IType arrayType = typeRepository.getType(arrayTypeName);
190
191
			return new JavaTypeDeclaration(
192
				typeRepository,
193
				arrayType,
194
				genericArrayType.getGenericComponentType(),
195
				true
196
			);
197
		}
198
199
		return buildTypeDeclaration((Class<?>) genericType);
200
	}
201
202
	private String elementType(String typeName) {
203
204
		if (typeName.equals("boolean")) return "Z";
205
		if (typeName.equals("byte"))    return "B";
206
		if (typeName.equals("char"))    return "C";
207
		if (typeName.equals("double"))  return "D";
208
		if (typeName.equals("float"))   return "F";
209
		if (typeName.equals("int"))     return "I";
210
		if (typeName.equals("long"))    return "J";
211
		if (typeName.equals("short"))   return "S";
212
213
		return "L";
214
	}
215
216
	/**
217
	 * {@inheritDoc}
218
	 */
219
	public int getDimensionality() {
220
		if (array) {
221
			String name = type.getName();
222
			int index = 0;
223
			while (name.charAt(index) == '[') {
224
				index++;
225
			}
226
			return index;
227
		}
228
		return 0;
229
	}
230
231
	/**
232
	 * {@inheritDoc}
233
	 */
234
	public IType getType() {
235
		return type;
236
	}
237
238
	private IType getType(Class<?> type) {
239
		return typeRepository.getType(type);
240
	}
241
242
	/**
243
	 * {@inheritDoc}
244
	 */
245
	public ITypeDeclaration[] getTypeParameters() {
246
		if (genericTypes == null) {
247
			if (genericType == null) {
248
				genericTypes = new ITypeDeclaration[0];
249
			}
250
			else {
251
				genericTypes = buildParameterTypes();
252
			}
253
		}
254
		return genericTypes;
255
	}
256
257
	/**
258
	 * {@inheritDoc}
259
	 */
260
	public boolean isArray() {
261
		return array;
262
	}
263
264
	/**
265
	 * {@inheritDoc}
266
	 */
267
	@Override
268
	public String toString() {
269
		return (genericType != null) ? genericType.toString() : type.toString();
270
	}
271
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpql/JpaConstructor.java (+140 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
5
 * which accompanies this distribution.
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.core.internal.jpql;
15
16
import org.eclipse.jdt.core.dom.IMethodBinding;
17
import org.eclipse.jdt.core.dom.ITypeBinding;
18
import org.eclipse.persistence.jpa.jpql.spi.IConstructor;
19
import org.eclipse.persistence.jpa.jpql.spi.IType;
20
import org.eclipse.persistence.jpa.jpql.spi.ITypeDeclaration;
21
import org.eclipse.persistence.jpa.jpql.spi.ITypeRepository;
22
23
/**
24
 * The concrete implementation of {@link IConstructor} that is wrapping the design-time
25
 * representation of a Java constructor.
26
 *
27
 * @version 3.0
28
 * @since 3.0
29
 * @author Pascal Filion
30
 */
31
final class JpaConstructor implements IConstructor {
32
33
	/**
34
	 * The design-time representation of a Java constructor.
35
	 */
36
	private IMethodBinding constructor;
37
38
	/**
39
	 * The cached {@link ITypeDeclaration ITypeDeclarations} representing each of the constructor's
40
	 * parameter types.
41
	 */
42
	private ITypeDeclaration[] typeDeclarations;
43
44
	/**
45
	 * The type owning this constructor.
46
	 */
47
	private JpaType type;
48
49
	/**
50
	 * Creates a new <code>JpaConstructor</code>.
51
	 *
52
	 * @param type The type owning the constructor
53
	 * @param constructor The design-time representation of a Java constructor
54
	 */
55
	JpaConstructor(JpaType type, IMethodBinding constructor) {
56
		super();
57
		this.type        = type;
58
		this.constructor = constructor;
59
	}
60
61
	private ITypeDeclaration buildTypeDeclaration(ITypeBinding parameterType) {
62
63
		boolean array = parameterType.isArray();
64
		String typeParameterName;
65
66
		if (array) {
67
			ITypeBinding componentType = parameterType.getComponentType();
68
69
			// <T>[] or <? extends <class_name>>[]
70
			if (componentType.isTypeVariable() ||
71
			    componentType.isParameterizedType()) {
72
73
				typeParameterName = componentType.getErasure().getQualifiedName();
74
			}
75
			else {
76
				typeParameterName = componentType.getQualifiedName();
77
			}
78
79
			// Now for the type arguments, we have to use the component type
80
			parameterType = componentType;
81
		}
82
		// <T> or <? extends <class_name>>
83
		else if (parameterType.isTypeVariable() ||
84
		         parameterType.isParameterizedType()) {
85
86
			typeParameterName = parameterType.getErasure().getQualifiedName();
87
		}
88
		else {
89
			typeParameterName = parameterType.getQualifiedName();
90
		}
91
92
		// Retrieve the fully qualified name of the type
93
		ITypeRepository typeRepository = type.getTypeRepository();
94
		ITypeBinding[] typeArguments = parameterType.getTypeArguments();
95
		ITypeDeclaration[] genericTypes = new ITypeDeclaration[typeArguments.length];
96
		int index = 0;
97
98
		for (ITypeBinding typeArgument : typeArguments) {
99
			String genericTypeName = typeArgument.getErasure().getQualifiedName();
100
			IType genericType = typeRepository.getType(genericTypeName);
101
			genericTypes[index++] = genericType.getTypeDeclaration();
102
		}
103
104
		return new JpaTypeDeclaration(
105
			typeRepository.getType(typeParameterName),
106
			genericTypes,
107
			parameterType.getDimensions()
108
		);
109
	}
110
111
	private ITypeDeclaration[] buildTypeDeclarations() {
112
113
		ITypeBinding[] parameterTypes = constructor.getParameterTypes();
114
		ITypeDeclaration[] declarations = new ITypeDeclaration[parameterTypes.length];
115
116
		for (int index = declarations.length; --index >= 0; ) {
117
			declarations[index] = buildTypeDeclaration(parameterTypes[index]);
118
		}
119
120
		return declarations;
121
	}
122
123
	/**
124
	 * {@inheritDoc}
125
	 */
126
	public ITypeDeclaration[] getParameterTypes() {
127
		if (typeDeclarations == null) {
128
			typeDeclarations = buildTypeDeclarations();
129
		}
130
		return typeDeclarations;
131
	}
132
133
	/**
134
	 * {@inheritDoc}
135
	 */
136
	@Override
137
	public String toString() {
138
		return constructor.toString();
139
	}
140
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpql/JpaEmbeddable.java (+63 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
5
 * which accompanies this distribution.
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.core.internal.jpql;
15
16
import org.eclipse.jpt.jpa.core.context.Embeddable;
17
import org.eclipse.persistence.jpa.jpql.spi.IEmbeddable;
18
import org.eclipse.persistence.jpa.jpql.spi.IManagedTypeVisitor;
19
20
/**
21
 * The concrete implementation of {@link IEmbeddable} that is wrapping the design-time
22
 * representation of a JPA embeddable.
23
 *
24
 * @version 3.0
25
 * @since 3.0
26
 * @author Pascal Filion
27
 */
28
final class JpaEmbeddable extends JpaManagedType
29
                          implements IEmbeddable {
30
31
	/**
32
	 * Creates a new <code>JpaEmbeddable</code>.
33
	 *
34
	 * @param provider The provider of JPA managed types
35
	 * @param embeddable The design-time model object wrapped by this class
36
	 */
37
	JpaEmbeddable(JpaManagedTypeProvider provider, Embeddable embeddable) {
38
		super(provider, embeddable);
39
	}
40
41
	/**
42
	 * {@inheritDoc}
43
	 */
44
	public void accept(IManagedTypeVisitor visitor) {
45
		visitor.visit(this);
46
	}
47
48
	/**
49
	 * {@inheritDoc}
50
	 */
51
	@Override
52
	Embeddable getManagedType() {
53
		return (Embeddable) super.getManagedType();
54
	}
55
56
	/**
57
	 * {@inheritDoc}
58
	 */
59
	@Override
60
	public String toString() {
61
		return getType().getName();
62
	}
63
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpql/JpaEntity.java (+111 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
5
 * which accompanies this distribution.
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.core.internal.jpql;
15
16
import java.util.HashMap;
17
import java.util.ListIterator;
18
import java.util.Map;
19
import org.eclipse.jpt.jpa.core.context.Entity;
20
import org.eclipse.jpt.jpa.core.context.NamedQuery;
21
import org.eclipse.persistence.jpa.jpql.spi.IEntity;
22
import org.eclipse.persistence.jpa.jpql.spi.IManagedTypeVisitor;
23
import org.eclipse.persistence.jpa.jpql.spi.IQuery;
24
25
/**
26
 * The concrete implementation of {@link IEntity} that is wrapping the design-time representation
27
 * of a JPA entity.
28
 *
29
 * @version 3.0
30
 * @since 3.0
31
 * @author Pascal Filion
32
 */
33
abstract class JpaEntity extends JpaManagedType
34
                         implements IEntity {
35
36
	/**
37
	 * The cached used to quickly retrieve any queries that have been cached.
38
	 */
39
	private Map<String, IQuery> queries;
40
41
	/**
42
	 * Creates a new <code>JpaEntity</code>.
43
	 *
44
	 * @param provider The provider of JPA managed types
45
	 * @param entity The design-time model object wrapped by this class
46
	 */
47
	JpaEntity(JpaManagedTypeProvider provider, Entity entity) {
48
		super(provider, entity);
49
	}
50
51
	/**
52
	 * {@inheritDoc}
53
	 */
54
	public void accept(IManagedTypeVisitor visitor) {
55
		visitor.visit(this);
56
	}
57
58
	final IQuery buildQuery(JpaManagedTypeProvider provider, NamedQuery namedQuery) {
59
		return new JpaQuery(provider, namedQuery);
60
	}
61
62
	/**
63
	 * {@inheritDoc}
64
	 */
65
	@Override
66
	Entity getManagedType() {
67
		return (Entity) super.getManagedType();
68
	}
69
70
	/**
71
	 * {@inheritDoc}
72
	 */
73
	public final String getName() {
74
		return getManagedType().getName();
75
	}
76
77
	/**
78
	 * {@inheritDoc}
79
	 */
80
	public IQuery getNamedQuery(String queryName) {
81
		initializeQueries();
82
		return queries.get(queryName);
83
	}
84
85
	private void initializeQueries() {
86
		if (queries == null) {
87
			queries = new HashMap<String, IQuery>();
88
			initializeQueries(queries);
89
		}
90
	}
91
92
	void initializeQueries(Map<String, IQuery> queries) {
93
		JpaManagedTypeProvider provider = getProvider();
94
		for (ListIterator<NamedQuery> iter = namedQueries(); iter.hasNext(); ) {
95
			NamedQuery namedQuery = iter.next();
96
			queries.put(namedQuery.getName(), buildQuery(provider, namedQuery));
97
		}
98
	}
99
100
	private ListIterator<NamedQuery> namedQueries() {
101
		return getManagedType().getQueryContainer().namedQueries();
102
	}
103
104
	/**
105
	 * {@inheritDoc}
106
	 */
107
	@Override
108
	public String toString() {
109
		return getName();
110
	}
111
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpql/JpaJpqlQueryHelper.java (+245 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
5
 * which accompanies this distribution.
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.core.internal.jpql;
15
16
import java.util.List;
17
import org.eclipse.jpt.common.core.internal.utility.SimpleTextRange;
18
import org.eclipse.jpt.common.core.utility.TextRange;
19
import org.eclipse.jpt.jpa.core.context.NamedQuery;
20
import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages;
21
import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages;
22
import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationPreferences;
23
import org.eclipse.persistence.jpa.jpql.ExpressionTools;
24
import org.eclipse.persistence.jpa.jpql.JPQLQueryHelper;
25
import org.eclipse.persistence.jpa.jpql.JPQLQueryProblem;
26
import org.eclipse.persistence.jpa.jpql.spi.IQuery;
27
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
28
29
/**
30
 * This helper can perform the following operations over a JPQL query:
31
 * <ul>
32
 * <li>Calculates the result type of a query: {@link #getResultType()};</li>
33
 * <li>Calculates the type of an input parameter: {@link #getParameterType(String)}.</li>
34
 * <li>Calculates the possible choices to complete the query from a given
35
 *     position (used for content assist): {@link #buildContentAssistItems(int)}.</li>
36
 * <li>Validates the query by introspecting its grammar and semantic:
37
 *     <ul>
38
 *     <li>{@link #validate()},</li>
39
 *     <li>{@link #validateGrammar()},</li>
40
 *     <li>{@link #validateSemantic()}.</li>
41
 *     </ul></li>
42
 *
43
 * @version 3.0
44
 * @since 3.0
45
 * @author Pascal Filion
46
 */
47
@SuppressWarnings("nls")
48
public final class JpaJpqlQueryHelper extends JPQLQueryHelper {
49
50
	/**
51
	 * Caches the provider in order to prevent recreating the SPI representation of the JPA artifacts
52
	 * more than once.
53
	 */
54
	private JpaManagedTypeProvider managedTypeProvider;
55
56
	/**
57
	 * Creates a new <code>JpaQueryHelper</code>.
58
	 */
59
	public JpaJpqlQueryHelper() {
60
		super();
61
	}
62
63
	/**
64
	 * Calculates the start and end positions by adjusting them to be at the same position within
65
	 * <em>jpqlQuery</em>, which may differ from <em>parsedJpqlQuery</em> since the parsed tree does
66
	 * not keep track of multiple whitespace. The range is also increased if the start and end
67
	 * positions are the same.
68
	 *
69
	 * @param problem The {@link JPQLQueryProblem problem} that was found in the JPQL query, which is
70
	 * either a grammatical or semantic problem
71
	 * @param parsedJpqlQuery The string representation of the parsed tree representation of the JPQL
72
	 * query
73
	 * @param actualQuery The actual JPQL query that was parsed and validated
74
	 * @return The start and end positions, which may have been adjusted
75
	 */
76
	public int[] buildPositions(JPQLQueryProblem problem, String parsedJpqlQuery, String actualQuery) {
77
78
		int startPosition = problem.getStartPosition();
79
		int endPosition   = problem.getEndPosition();
80
81
		// If the start and end positions are the same, then expand the text range
82
		if (startPosition == endPosition) {
83
			startPosition = Math.max(startPosition - 1, 0);
84
		}
85
86
		// Reposition the cursor so it's correctly positioned in the actual query, which is the
87
		// since it may contains more than one whitespace for a single whitespace
88
		int newStartPosition = ExpressionTools.repositionCursor(parsedJpqlQuery, startPosition, actualQuery);
89
90
		if (newStartPosition != startPosition) {
91
			endPosition  += (newStartPosition - startPosition);
92
			startPosition = newStartPosition;
93
		}
94
95
		return new int[] { startPosition, endPosition };
96
	}
97
98
	/**
99
	 * Creates a new {@link IMessage} for the given {@link JPQLQueryProblem}.
100
	 *
101
	 * @param namedQuery The model object for which a new {@link IMessage} is creating describing the
102
	 * problem
103
	 * @param problem The {@link JPQLQueryProblem problem} that was found in the JPQL query, which is
104
	 * either a grammatical or semantic problem
105
	 * @param textRange The range of the JPQL query in the Java source file
106
	 * @param parsedJpqlQuery The string representation of the parsed tree representation of the JPQL
107
	 * query, which may differ from the actual JPQL query since it does not keep more than one
108
	 * whitespace
109
	 * @param actualQuery The actual JPQL query that was parsed and validated
110
	 * @param offset This offset is used to move the start position
111
	 * @return A new {@link IMessage} that has the required information to display the problem
112
	 * underline and the error message in the Problems view
113
	 */
114
	private IMessage buildProblem(NamedQuery namedQuery,
115
	                              TextRange textRange,
116
	                              JPQLQueryProblem problem,
117
	                              String parsedJpqlQuery,
118
	                              String actualQuery,
119
	                              int offset) {
120
121
		// Convert the positions from the parsed JPQL query to the actual JPQL query
122
		int[] positions = buildPositions(problem, parsedJpqlQuery, actualQuery);
123
124
		// Now convert the adjusted positions once again to be in the query where the escape
125
		// characters are in their literal forms
126
		int[] newStartPosition = { positions[0] };
127
		ExpressionTools.escape(actualQuery, newStartPosition);
128
		int escapeOffset = positions[0] - newStartPosition[0];
129
130
		positions[0] -= escapeOffset;
131
		positions[1] -= escapeOffset;
132
133
		// Create the text range of the problem
134
		textRange = new SimpleTextRange(
135
			textRange.getOffset() + positions[0] + offset,
136
			positions[1] - positions[0],
137
			textRange.getLineNumber()
138
		);
139
140
		// Now create the message
141
		IMessage message = DefaultJpaValidationMessages.buildMessage(
142
			severity(namedQuery),
143
			problem.getMessageKey(),
144
			problem.getMessageArguments(),
145
			namedQuery,
146
			textRange
147
		);
148
		message.setBundleName("jpa_jpql_validation");
149
		return message;
150
	}
151
152
	private JpaManagedTypeProvider buildProvider(NamedQuery query) {
153
		try {
154
			return new JpaPersistenceUnit(query.getJpaProject(), query.getPersistenceUnit());
155
		}
156
		catch (Exception e) {
157
			return new JpaMappingFile(query.getJpaProject(), query.getMappingFileRoot().getParent());
158
		}
159
	}
160
161
	/**
162
	 * Disposes the provider so the application metadata is not kept in memory.
163
	 */
164
	public void disposeProvider() {
165
		managedTypeProvider = null;
166
	}
167
168
	/**
169
	 * Sets the given named query and string representation of the JPQL query.
170
	 *
171
	 * @param namedQuery The model object where the JPQL query is stored
172
	 * @param actualQuery The actual JPQL query, which can differ from the one owned by the model
173
	 * object, which happens when the model is out of sync because it has not been updated yet
174
	 */
175
	public void setQuery(NamedQuery namedQuery, String actualQuery) {
176
177
		if (managedTypeProvider == null) {
178
			managedTypeProvider = buildProvider(namedQuery);
179
		}
180
181
		IQuery query = new JpaQuery(managedTypeProvider, namedQuery, actualQuery);
182
		super.setQuery(query);
183
	}
184
185
	/**
186
	 * Retrieve the severity that is associated to JPQL query validation, which cannot be retrieved
187
	 * using the JPQL problem message key.
188
189
	 * @param targetObject The object for which a new {@link IMessage} is creating describing the
190
	 * problem
191
	 * @return The global severity for validating JPQL queries
192
	 */
193
	private int severity(Object targetObject) {
194
		return JpaValidationPreferences.getProblemSeverityPreference(
195
			targetObject,
196
			JpaValidationMessages.JPQL_QUERY_VALIDATION
197
		);
198
	}
199
200
	private boolean shouldValidate(NamedQuery namedQuery) {
201
		return JpaValidationPreferences.getProblemSeverityPreference(
202
			namedQuery,
203
			JpaValidationMessages.JPQL_QUERY_VALIDATION
204
		) == -1;
205
	}
206
207
	/**
208
	 * Validates the given {@link NamedQuery} by validating the JPQL query.
209
	 *
210
	 * @param namedQuery The JPQL query to validate
211
	 * @param jpqlQuery The JPQL query, which might be different from what the model object since
212
	 * the escape characters should not be in their literal forms (should have '\r' and not '\\r')
213
	 * @param textRange The range of the JPQL query string within the document
214
	 * @param offset This offset is used to move the start position
215
	 * @param messages The list of {@link IMessage IMessages} that will be used to add validation
216
	 * problems
217
	 */
218
	public void validate(NamedQuery namedQuery,
219
	                     String jpqlQuery,
220
	                     TextRange textRange,
221
	                     int offset,
222
	                     List<IMessage> messages) {
223
224
		// Make this quick check so we don't validate the query, which is time consuming
225
		if (shouldValidate(namedQuery)) {
226
227
			setQuery(namedQuery, jpqlQuery);
228
			String parsedJpqlQuery = getParsedJPQLQuery();
229
230
			for (JPQLQueryProblem problem : validate()) {
231
232
				IMessage message = buildProblem(
233
					namedQuery,
234
					textRange,
235
					problem,
236
					parsedJpqlQuery,
237
					jpqlQuery,
238
					offset
239
				);
240
241
				messages.add(message);
242
			}
243
		}
244
	}
245
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpql/JpaManagedType.java (+136 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
5
 * which accompanies this distribution.
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.core.internal.jpql;
15
16
import java.util.Collections;
17
import java.util.HashMap;
18
import java.util.Iterator;
19
import java.util.Map;
20
import org.eclipse.jpt.jpa.core.context.AttributeMapping;
21
import org.eclipse.jpt.jpa.core.context.TypeMapping;
22
import org.eclipse.persistence.jpa.jpql.spi.IManagedType;
23
import org.eclipse.persistence.jpa.jpql.spi.IMapping;
24
import org.eclipse.persistence.jpa.jpql.spi.IType;
25
26
/**
27
 * The abstract definition of {@link IManagedType} defined for wrapping the design-time mapped class
28
 * object.
29
 *
30
 * @version 3.0
31
 * @since 3.0
32
 * @author Pascal Filion
33
 */
34
abstract class JpaManagedType implements IManagedType {
35
36
	/**
37
	 * The design-time model object wrapped by this class.
38
	 */
39
	private final TypeMapping managedType;
40
41
	/**
42
	 * The cached collection of {@link IMapping mappings} that prevent rebuilding them every time one
43
	 * is requested.
44
	 */
45
	private Map<String, IMapping> mappings;
46
47
	/**
48
	 * The provider of JPA managed types.
49
	 */
50
	private final JpaManagedTypeProvider provider;
51
52
	/**
53
	 * The cached type of this managed type.
54
	 */
55
	private IType type;
56
57
	/**
58
	 * Creates a new <code>JDeveloperManagedType</code>.
59
	 *
60
	 * @param managedType The provider of JPA managed types
61
	 * @param mappedClass The design-time model object wrapped by this class
62
	 */
63
	JpaManagedType(JpaManagedTypeProvider provider, TypeMapping managedType) {
64
		super();
65
		this.provider    = provider;
66
		this.managedType = managedType;
67
	}
68
69
	private IMapping buildMapping(AttributeMapping mapping) {
70
		return new JpaMapping(this, mapping);
71
	}
72
73
	private Map<String, IMapping> buildMappings() {
74
		Map<String, IMapping> mappings = new HashMap<String, IMapping>();
75
		for (Iterator<AttributeMapping> iter = managedType.allAttributeMappings(); iter.hasNext(); ) {
76
			AttributeMapping mapping = iter.next();
77
			mappings.put(mapping.getName(), buildMapping(mapping));
78
		}
79
		return mappings;
80
	}
81
82
	/**
83
	 * {@inheritDoc}
84
	 */
85
	public int compareTo(IManagedType managedType) {
86
		return getType().getName().compareTo(managedType.getType().getName());
87
	}
88
89
	/**
90
	 * Returns the encapsulated model object.
91
	 *
92
	 * @return The managed type wrapped by this external form
93
	 */
94
	TypeMapping getManagedType() {
95
		return managedType;
96
	}
97
98
	/**
99
	 * {@inheritDoc}
100
	 */
101
	public final IMapping getMappingNamed(String name) {
102
		initializeMappings();
103
		return mappings.get(name);
104
	}
105
106
	/**
107
	 * {@inheritDoc}
108
	 */
109
	public final JpaManagedTypeProvider getProvider() {
110
		return provider;
111
	}
112
113
	/**
114
	 * {@inheritDoc}
115
	 */
116
	public final IType getType() {
117
		if (type == null) {
118
			type = provider.getTypeRepository().getType(managedType.getPersistentType().getName());
119
		}
120
		return type;
121
	}
122
123
	private void initializeMappings() {
124
		if (mappings == null) {
125
			mappings = buildMappings();
126
		}
127
	}
128
129
	/**
130
	 * {@inheritDoc}
131
	 */
132
	public final Iterable<IMapping> mappings() {
133
		initializeMappings();
134
		return Collections.unmodifiableCollection(mappings.values());
135
	}
136
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpql/JpaManagedTypeProvider.java (+277 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
5
 * which accompanies this distribution.
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.core.internal.jpql;
15
16
import java.util.ArrayList;
17
import java.util.Collection;
18
import java.util.Collections;
19
import java.util.HashMap;
20
import java.util.Iterator;
21
import java.util.Map;
22
import org.eclipse.jpt.jpa.core.JpaFacet;
23
import org.eclipse.jpt.jpa.core.JpaPlatform;
24
import org.eclipse.jpt.jpa.core.JpaProject;
25
import org.eclipse.jpt.jpa.core.context.Embeddable;
26
import org.eclipse.jpt.jpa.core.context.Entity;
27
import org.eclipse.jpt.jpa.core.context.MappedSuperclass;
28
import org.eclipse.jpt.jpa.core.context.PersistentType;
29
import org.eclipse.jpt.jpa.core.context.TypeMapping;
30
import org.eclipse.jpt.jpa.core.context.persistence.PersistentTypeContainer;
31
import org.eclipse.jpt.jpa.core.internal.jpa1.GenericJpaProject;
32
import org.eclipse.persistence.jpa.jpql.spi.IEmbeddable;
33
import org.eclipse.persistence.jpa.jpql.spi.IEntity;
34
import org.eclipse.persistence.jpa.jpql.spi.IJPAVersion;
35
import org.eclipse.persistence.jpa.jpql.spi.IManagedType;
36
import org.eclipse.persistence.jpa.jpql.spi.IManagedTypeProvider;
37
import org.eclipse.persistence.jpa.jpql.spi.IManagedTypeVisitor;
38
import org.eclipse.persistence.jpa.jpql.spi.IMappedSuperclass;
39
import org.eclipse.persistence.jpa.jpql.spi.IPlatform;
40
import org.eclipse.persistence.jpa.jpql.spi.IType;
41
42
/**
43
 * The abstract implementation of {@link IManagedTypeProvider} that is wrapping the design-time
44
 * representation of a provider of managed types.
45
 *
46
 * @version 3.0
47
 * @since 3.0
48
 * @author Pascal Filion
49
 */
50
abstract class JpaManagedTypeProvider implements IManagedTypeProvider {
51
52
	/**
53
	 * The filtered collection of managed types that are the abstract schema types.
54
	 */
55
	private Collection<IEntity> abstractSchemaTypes;
56
57
	/**
58
	 * The project that gives access to the application's metadata.
59
	 */
60
	private final JpaProject jpaProject;
61
62
	/**
63
	 * The cached {@link IManagedType managed types}.
64
	 */
65
	private Map<String, IManagedType> managedTypes;
66
67
	/**
68
	 * The design-time provider of managed types.
69
	 */
70
	private final PersistentTypeContainer persistentTypeContainer;
71
72
	/**
73
	 * The external form of a type repository.
74
	 */
75
	private JpaTypeRepository typeRepository;
76
77
	/**
78
	 * The version of the Java Persistence this entity for which it was defined.
79
	 */
80
	private IJPAVersion version;
81
82
	/**
83
	 * Creates a new <code>JpaManagedTypeProvider</code>.
84
	 *
85
	 * @param jpaProject The project that gives access to the application's metadata
86
	 * @param persistentTypeContainer The design-time provider of managed types
87
	 */
88
	JpaManagedTypeProvider(JpaProject jpaProject, PersistentTypeContainer persistentTypeContainer) {
89
90
		super();
91
		this.jpaProject = jpaProject;
92
		this.persistentTypeContainer = persistentTypeContainer;
93
	}
94
95
	/**
96
	 * {@inheritDoc}
97
	 */
98
	public Iterable<IEntity> abstractSchemaTypes() {
99
		if (abstractSchemaTypes == null) {
100
			initializeManagedTypes();
101
			EntityCollector visitor = new EntityCollector();
102
			for (IManagedType managedType : managedTypes.values()) {
103
				managedType.accept(visitor);
104
			}
105
			abstractSchemaTypes = visitor.entities;
106
		}
107
		return Collections.unmodifiableCollection(abstractSchemaTypes);
108
	}
109
110
	abstract JpaEntity buildEntity(TypeMapping mappedClass);
111
112
	private IManagedType buildManagedType(PersistentType persistentType) {
113
114
		TypeMapping mappedClass = persistentType.getMapping();
115
116
		if (mappedClass instanceof Entity) {
117
			return buildEntity(mappedClass);
118
		}
119
120
		if (mappedClass instanceof MappedSuperclass) {
121
			return new JpaMappedSuperclass(this, (MappedSuperclass) mappedClass);
122
		}
123
124
		if (mappedClass instanceof Embeddable) {
125
			return new JpaEmbeddable(this, (Embeddable) mappedClass);
126
		}
127
128
		return new JpaNullManagedType(this, mappedClass);
129
	}
130
131
	private Map<String, IManagedType> buildManagedTypes() {
132
		Map<String, IManagedType> managedTypes = new HashMap<String, IManagedType>();
133
		for (Iterator<? extends PersistentType> iter = persistenceTypes(); iter.hasNext(); ) {
134
			PersistentType persistentType = iter.next();
135
			if (persistentType != null) {
136
				managedTypes.put(persistentType.getMapping().getName(), buildManagedType(persistentType));
137
			}
138
		}
139
		return managedTypes;
140
	}
141
142
	private IJPAVersion convert(JpaPlatform.Version version) {
143
144
		String jpaVersion = version.getJpaVersion();
145
146
		if (JpaFacet.VERSION_1_0.getVersionString().equals(jpaVersion)) {
147
			return IJPAVersion.VERSION_1_0;
148
		}
149
150
		return IJPAVersion.VERSION_2_0;
151
	}
152
153
	/**
154
	 * {@inheritDoc}
155
	 */
156
	public IManagedType getManagedType(IType type) {
157
158
		initializeManagedTypes();
159
160
		for (IManagedType managedType : managedTypes.values()) {
161
			if (managedType.getType() == type) {
162
				return managedType;
163
			}
164
		}
165
166
		return null;
167
	}
168
169
	/**
170
	 * {@inheritDoc}
171
	 */
172
	public IManagedType getManagedType(String abstractSchemaName) {
173
		initializeManagedTypes();
174
		return managedTypes.get(abstractSchemaName);
175
	}
176
177
	/**
178
	 * Returns the container of managed types.
179
	 *
180
	 * @return The container of managed types
181
	 */
182
	PersistentTypeContainer getPersistentTypeContainer() {
183
		return persistentTypeContainer;
184
	}
185
186
	/**
187
	 * {@inheritDoc}
188
	 */
189
	public IPlatform getPlatform() {
190
		return (jpaProject instanceof GenericJpaProject) ? IPlatform.JAVA  : IPlatform.ECLIPSE_LINK;
191
	}
192
193
	/**
194
	 * Returns the encapsulated {@link PersistentType}, which is the actual object.
195
	 *
196
	 * @return The design-time representation of a managed type provider
197
	 */
198
	PersistentTypeContainer getProvider() {
199
		return persistentTypeContainer;
200
	}
201
202
	/**
203
	 * {@inheritDoc}
204
	 */
205
	public JpaTypeRepository getTypeRepository() {
206
		if (typeRepository == null) {
207
			typeRepository = new JpaTypeRepository(jpaProject.getJavaProject());
208
		}
209
		return typeRepository;
210
	}
211
212
	/**
213
	 * {@inheritDoc}
214
	 */
215
	public IJPAVersion getVersion() {
216
		if (version == null) {
217
			version = convert(jpaProject.getJpaPlatform().getJpaVersion());
218
		}
219
		return version;
220
	}
221
222
	private void initializeManagedTypes() {
223
		if (managedTypes == null) {
224
			managedTypes = buildManagedTypes();
225
		}
226
	}
227
228
	/**
229
	 * {@inheritDoc}
230
	 */
231
	public Iterable<IManagedType> managedTypes() {
232
		initializeManagedTypes();
233
		return Collections.unmodifiableCollection(managedTypes.values());
234
	}
235
236
	/**
237
	 * Retrieves the managed types from the design-time provider.
238
	 *
239
	 * @return The managed types that are defined only in the provider
240
	 */
241
	abstract Iterator<? extends PersistentType> persistenceTypes();
242
243
	private static class EntityCollector implements IManagedTypeVisitor {
244
245
		/**
246
		 * The collection of {@link IEntity entities} that got visited.
247
		 */
248
		private final Collection<IEntity> entities;
249
250
		/**
251
		 * Creates a new <code>EntityCollector</code>.
252
		 */
253
		EntityCollector() {
254
			super();
255
			entities = new ArrayList<IEntity>();
256
		}
257
258
		/**
259
		 * {@inheritDoc}
260
		 */
261
		public void visit(IEmbeddable embeddable) {
262
		}
263
264
		/**
265
		 * {@inheritDoc}
266
		 */
267
		public void visit(IEntity entity) {
268
			entities.add(entity);
269
		}
270
271
		/**
272
		 * {@inheritDoc}
273
		 */
274
		public void visit(IMappedSuperclass mappedSuperclass) {
275
		}
276
	}
277
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpql/JpaMappedSuperclass.java (+63 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
5
 * which accompanies this distribution.
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.core.internal.jpql;
15
16
import org.eclipse.jpt.jpa.core.context.MappedSuperclass;
17
import org.eclipse.persistence.jpa.jpql.spi.IManagedTypeVisitor;
18
import org.eclipse.persistence.jpa.jpql.spi.IMappedSuperclass;
19
20
/**
21
 * The concrete implementation of {@link IMappedSuperclass} that is wrapping the design-time
22
 * representation of a JPA mapped superclass.
23
 *
24
 * @version 3.0
25
 * @since 3.0
26
 * @author Pascal Filion
27
 */
28
final class JpaMappedSuperclass extends JpaManagedType
29
                                implements IMappedSuperclass {
30
31
	/**
32
	 * Creates a new <code>JpaMappedSuperclass</code>.
33
	 *
34
	 * @param provider The provider of JPA managed types
35
	 * @param mappedSuperclass The design-time model object wrapped by this class
36
	 */
37
	JpaMappedSuperclass(JpaManagedTypeProvider provider, MappedSuperclass mappedSuperclass) {
38
		super(provider, mappedSuperclass);
39
	}
40
41
	/**
42
	 * {@inheritDoc}
43
	 */
44
	public void accept(IManagedTypeVisitor visitor) {
45
		visitor.visit(this);
46
	}
47
48
	/**
49
	 * {@inheritDoc}
50
	 */
51
	@Override
52
	MappedSuperclass getManagedType() {
53
		return (MappedSuperclass) super.getManagedType();
54
	}
55
56
	/**
57
	 * {@inheritDoc}
58
	 */
59
	@Override
60
	public String toString() {
61
		return getType().getName();
62
	}
63
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpql/JpaMapping.java (+270 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
5
 * which accompanies this distribution.
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.core.internal.jpql;
15
16
import java.lang.annotation.Annotation;
17
import java.util.Iterator;
18
import java.util.List;
19
import org.eclipse.jpt.common.utility.internal.CollectionTools;
20
import org.eclipse.jpt.common.utility.internal.StringTools;
21
import org.eclipse.jpt.common.utility.internal.iterators.TransformationIterator;
22
import org.eclipse.jpt.jpa.core.MappingKeys;
23
import org.eclipse.jpt.jpa.core.context.AttributeMapping;
24
import org.eclipse.jpt.jpa.core.context.PersistentAttribute;
25
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
26
import org.eclipse.jpt.jpa.core.jpa2.MappingKeys2_0;
27
import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentAttribute;
28
import org.eclipse.persistence.jpa.jpql.spi.IManagedType;
29
import org.eclipse.persistence.jpa.jpql.spi.IMapping;
30
import org.eclipse.persistence.jpa.jpql.spi.IMappingType;
31
import org.eclipse.persistence.jpa.jpql.spi.IType;
32
import org.eclipse.persistence.jpa.jpql.spi.ITypeDeclaration;
33
34
/**
35
 * The concrete implementation of {@link IMapping} that is wrapping the design-time representation
36
 * of a mapping.
37
 *
38
 * @version 3.0
39
 * @since 3.0
40
 * @author Pascal Filion
41
 */
42
@SuppressWarnings("nls")
43
final class JpaMapping implements IMapping {
44
45
	/**
46
	 * The design-time {@link AttributeMapping} wrapped by this class.
47
	 */
48
	private final AttributeMapping mapping;
49
50
	/**
51
	 * The type of the actual mapping.
52
	 */
53
	private IMappingType mappingType;
54
55
	/**
56
	 * The parent of this mapping.
57
	 */
58
	private final JpaManagedType parent;
59
60
	/**
61
	 * The {@link IType} of the property represented by the mapping.
62
	 */
63
	private IType type;
64
65
	/**
66
	 * The {@link ITypeDeclaration} of the property represented by the mapping.
67
	 */
68
	private ITypeDeclaration typeDeclaration;
69
70
	/**
71
	 * Creates a new <code>JpaMapping</code>.
72
	 *
73
	 * @param parent The parent of this mapping
74
	 * @param mapping The design-time {@link AttributeMapping} wrapped by this class
75
	 */
76
	JpaMapping(JpaManagedType parent, AttributeMapping mapping) {
77
		super();
78
		this.parent  = parent;
79
		this.mapping = mapping;
80
	}
81
82
	private ITypeDeclaration[] buildGenericTypeDeclarations() {
83
		JavaPersistentAttribute javaPersistentAttribute = mapping.getPersistentAttribute().getJavaPersistentAttribute();
84
		JavaResourcePersistentAttribute resource = javaPersistentAttribute.getResourcePersistentAttribute();
85
		List<ITypeDeclaration> declarations = CollectionTools.list(buildGenericTypeDeclarations(resource));
86
		return declarations.toArray(new ITypeDeclaration[declarations.size()]);
87
	}
88
89
	private Iterator<ITypeDeclaration> buildGenericTypeDeclarations(JavaResourcePersistentAttribute resource) {
90
		return new TransformationIterator<String, ITypeDeclaration>(resource.typeTypeArgumentNames()) {
91
			@Override
92
			protected ITypeDeclaration transform(String next) {
93
				return getTypeRepository().getType(next).getTypeDeclaration();
94
			}
95
		};
96
	}
97
98
	private ITypeDeclaration buildTypeDeclaration() {
99
100
		PersistentAttribute property = mapping.getPersistentAttribute();
101
		boolean array = property.getTypeName().endsWith("[]");
102
		int dimensionality = 0;
103
104
		if (array) {
105
			dimensionality = getType().getTypeDeclaration().getDimensionality();
106
		}
107
108
		return new JpaTypeDeclaration(
109
			getType(),
110
			buildGenericTypeDeclarations(),
111
			dimensionality
112
		);
113
	}
114
115
	/**
116
	 * {@inheritDoc}
117
	 */
118
	public int compareTo(IMapping mapping) {
119
		return getName().compareTo(mapping.getName());
120
	}
121
122
	/**
123
	 * {@inheritDoc}
124
	 */
125
	public IMappingType getMappingType() {
126
		if (mappingType == null) {
127
			getTypeDeclaration();
128
			mappingType = mappingType();
129
		}
130
		return mappingType;
131
	}
132
133
	/**
134
	 * {@inheritDoc}
135
	 */
136
	public String getName() {
137
		return mapping.getName();
138
	}
139
140
	/**
141
	 * {@inheritDoc}
142
	 */
143
	public IManagedType getParent() {
144
		return parent;
145
	}
146
147
	/**
148
	 * {@inheritDoc}
149
	 */
150
	public IType getType() {
151
		if (type == null) {
152
			PersistentAttribute property = mapping.getPersistentAttribute();
153
			type = getTypeRepository().getType(property.getTypeName());
154
		}
155
		return type;
156
	}
157
158
	/**
159
	 * {@inheritDoc}
160
	 */
161
	public ITypeDeclaration getTypeDeclaration() {
162
		if (typeDeclaration == null) {
163
			typeDeclaration = buildTypeDeclaration();
164
		}
165
		return typeDeclaration;
166
	}
167
168
	private JpaTypeRepository getTypeRepository() {
169
		return parent.getProvider().getTypeRepository();
170
	}
171
172
	/**
173
	 * {@inheritDoc}
174
	 */
175
	public boolean hasAnnotation(Class<? extends Annotation> annotationType) {
176
		JavaResourcePersistentAttribute attribute = mapping.getPersistentAttribute().getJavaPersistentAttribute().getResourcePersistentAttribute();
177
		return attribute.getAnnotation(annotationType.getName()) != null;
178
	}
179
180
	private IMappingType mappingType() {
181
182
		String type = mapping.getKey();
183
184
		// Basic
185
		if (type == MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY) {
186
			return IMappingType.BASIC;
187
		}
188
189
		// Embedded
190
		if (type == MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY) {
191
			return IMappingType.EMBEDDED;
192
		}
193
194
		// Embedded Id
195
		if (type == MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY) {
196
			return IMappingType.EMBEDDED_ID;
197
		}
198
199
		// Id
200
		if (type == MappingKeys.ID_ATTRIBUTE_MAPPING_KEY) {
201
			return IMappingType.ID;
202
		}
203
204
		// M:M
205
		if (type == MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY) {
206
			return IMappingType.MANY_TO_MANY;
207
		}
208
209
		// 1:M
210
		if (type == MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY) {
211
			return IMappingType.ONE_TO_MANY;
212
		}
213
214
		// M:1
215
		if (type == MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY) {
216
			return IMappingType.MANY_TO_ONE;
217
		}
218
219
		// 1:1
220
		if (type == MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY) {
221
			return IMappingType.ONE_TO_ONE;
222
		}
223
224
		// Version
225
		if (type == MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY) {
226
			return IMappingType.VERSION;
227
		}
228
229
		// Element Collection
230
		if (type == MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY) {
231
			return IMappingType.ELEMENT_COLLECTION;
232
		}
233
234
		// Basic Collection
235
//		if (type == EclipseLinkMappingKeys.BASIC_COLLECTION_ATTRIBUTE_MAPPING_KEY) {
236
//			return IMappingType.BASIC_COLLECTION;
237
//		}
238
//
239
//		// Basic Map
240
//		if (type == EclipseLinkMappingKeys.BASIC_MAP_ATTRIBUTE_MAPPING_KEY) {
241
//			return IMappingType.BASIC_MAP;
242
//		}
243
//
244
//		// Transformation
245
//		if (type == EclipseLinkMappingKeys.TRANSFORMATION_ATTRIBUTE_MAPPING_KEY) {
246
//			return IMappingType.TRANSFORMATION;
247
//		}
248
//
249
//		// Variable 1:1
250
//		if (type == EclipseLinkMappingKeys.VARIABLE_ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY) {
251
//			return IMappingType.VARIABLE_ONE_TO_ONE;
252
//		}
253
254
		return IMappingType.TRANSIENT;
255
	}
256
257
	/**
258
	 * {@inheritDoc}
259
	 */
260
	@Override
261
	public String toString() {
262
		StringBuilder sb = new StringBuilder();
263
		StringTools.buildSimpleToStringOn(this, sb);
264
		sb.append(", name=");
265
		sb.append(getName());
266
		sb.append(", mappingType=");
267
		sb.append(getMappingType());
268
		return sb.toString();
269
	}
270
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpql/JpaMappingFile.java (+65 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the 
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 
5
 * which accompanies this distribution. 
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at 
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.core.internal.jpql;
15
16
import java.util.Iterator;
17
import org.eclipse.jpt.jpa.core.JpaProject;
18
import org.eclipse.jpt.jpa.core.context.Entity;
19
import org.eclipse.jpt.jpa.core.context.MappingFile;
20
import org.eclipse.jpt.jpa.core.context.PersistentType;
21
import org.eclipse.jpt.jpa.core.context.TypeMapping;
22
23
/**
24
 * The concrete implementation that is wrapping the design-time representation of a mapping file.
25
 *
26
 * @version 3.0
27
 * @since 3.0
28
 * @author Pascal Filion
29
 */
30
public class JpaMappingFile extends JpaManagedTypeProvider {
31
32
	/**
33
	 * Creates a new <code>JpaMappingFile</code>.
34
	 * 
35
	 * @param jpaProject The project that gives access to the application's metadata
36
	 * @param persistentTypeContainer The design-time provider of managed types
37
	 */
38
	public JpaMappingFile(JpaProject jpaProject, MappingFile persistentTypeContainer) {
39
		super(jpaProject, persistentTypeContainer);
40
	}
41
42
	/**
43
	 * {@inheritDoc}
44
	 */
45
	@Override
46
	JpaEntity buildEntity(TypeMapping mappedClass) {
47
		return new JpaOrmEntity(this, (Entity) mappedClass);
48
	}
49
50
	/**
51
	 * {@inheritDoc}
52
	 */
53
	@Override
54
	protected MappingFile getPersistentTypeContainer() {
55
		return (MappingFile) super.getPersistentTypeContainer();
56
	}
57
58
	/**
59
	 * {@inheritDoc}
60
	 */
61
	@Override
62
	protected Iterator<? extends PersistentType> persistenceTypes() {
63
		return getPersistentTypeContainer().getPersistentTypes().iterator();
64
	}
65
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpql/JpaNullManagedType.java (+112 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
5
 * which accompanies this distribution.
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.core.internal.jpql;
15
16
import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable;
17
import org.eclipse.jpt.jpa.core.context.TypeMapping;
18
import org.eclipse.persistence.jpa.jpql.spi.IManagedType;
19
import org.eclipse.persistence.jpa.jpql.spi.IManagedTypeProvider;
20
import org.eclipse.persistence.jpa.jpql.spi.IManagedTypeVisitor;
21
import org.eclipse.persistence.jpa.jpql.spi.IMapping;
22
import org.eclipse.persistence.jpa.jpql.spi.IType;
23
24
/**
25
 * The concrete implementation of {@link IManagedType} that is wrapping the design-time
26
 * representation a "null" managed type.
27
 *
28
 * @version 3.0
29
 * @since 3.0
30
 * @author Pascal Filion
31
 */
32
final class JpaNullManagedType implements IManagedType {
33
34
	/**
35
	 * The provider of JPA managed types.
36
	 */
37
	private final JpaManagedTypeProvider provider;
38
39
	/**
40
	 * The cached {@link IType} of this "null" managed type.
41
	 */
42
	private IType type;
43
44
	/**
45
	 * The design-time model object wrapped by this class.
46
	 */
47
	private final TypeMapping typeMapping;
48
49
	/**
50
	 * Creates a new <code>JpaNullManagedType</code>.
51
	 *
52
	 * @param managedType The provider of JPA managed types
53
	 * @param typeMapping The design-time model object wrapped by this class
54
	 */
55
	JpaNullManagedType(JpaManagedTypeProvider provider, TypeMapping typeMapping) {
56
		super();
57
		this.provider    = provider;
58
		this.typeMapping = typeMapping;
59
	}
60
61
	/**
62
	 * {@inheritDoc}
63
	 */
64
	public void accept(IManagedTypeVisitor visitor) {
65
	}
66
67
	/**
68
	 * {@inheritDoc}
69
	 */
70
	public int compareTo(IManagedType managedType) {
71
		return getType().getName().compareTo(managedType.getType().getName());
72
	}
73
74
	/**
75
	 * {@inheritDoc}
76
	 */
77
	public IMapping getMappingNamed(String name) {
78
		return null;
79
	}
80
81
	/**
82
	 * {@inheritDoc}
83
	 */
84
	public IManagedTypeProvider getProvider() {
85
		return provider;
86
	}
87
88
	/**
89
	 * {@inheritDoc}
90
	 */
91
	public IType getType() {
92
		if (type == null) {
93
			type = provider.getTypeRepository().getType(typeMapping.getPersistentType().getName());
94
		}
95
		return type;
96
	}
97
98
	/**
99
	 * {@inheritDoc}
100
	 */
101
	public Iterable<IMapping> mappings() {
102
		return EmptyIterable.instance();
103
	}
104
105
	/**
106
	 * {@inheritDoc}
107
	 */
108
	@Override
109
	public String toString() {
110
		return getType().getName();
111
	}
112
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpql/JpaOrmEntity.java (+59 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
6
 *
7
 * Contributors:
8
 *     Oracle - initial API and implementation
9
 *******************************************************************************/
10
package org.eclipse.jpt.jpa.core.internal.jpql;
11
12
import java.util.ListIterator;
13
import java.util.Map;
14
import org.eclipse.jpt.jpa.core.context.Entity;
15
import org.eclipse.jpt.jpa.core.context.NamedQuery;
16
import org.eclipse.jpt.jpa.core.context.java.JavaTypeMapping;
17
import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType;
18
import org.eclipse.persistence.jpa.jpql.spi.IQuery;
19
20
/**
21
 * The concrete implementation of {@link IEntity} that is wrapping the design-time representation
22
 * of a JPA entity defined in an ORM configuration.
23
 *
24
 * @version 3.0
25
 * @since 3.0
26
 * @author Pascal Filion
27
 */
28
final class JpaOrmEntity extends JpaEntity {
29
30
	/**
31
	 * Creates a new <code>JpaOrmEntity</code>.
32
	 *
33
	 * @param provider The provider of JPA managed types
34
	 * @param entity The design-time model object wrapped by this class
35
	 */
36
	JpaOrmEntity(JpaMappingFile provider, Entity entity) {
37
		super(provider, entity);
38
	}
39
40
	/**
41
	 * {@inheritDoc}
42
	 */
43
	@Override
44
	void initializeQueries(Map<String, IQuery> queries) {
45
		super.initializeQueries(queries);
46
47
		JpaManagedTypeProvider provider = getProvider();
48
		OrmPersistentType type = (OrmPersistentType) getManagedType().getPersistentType();
49
		JavaTypeMapping mapping = type.getJavaPersistentType().getMapping();
50
51
		if (mapping instanceof Entity) {
52
			Entity entity = (Entity) mapping;
53
			for (ListIterator<NamedQuery> iter = entity.getQueryContainer().namedQueries(); iter.hasNext(); ) {
54
				NamedQuery namedQuery = iter.next();
55
				queries.put(namedQuery.getName(), buildQuery(provider, namedQuery));
56
			}
57
		}
58
	}
59
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpql/JpaPersistenceUnit.java (+81 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the 
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 
5
 * which accompanies this distribution. 
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at 
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.core.internal.jpql;
15
16
import java.util.Iterator;
17
import org.eclipse.jpt.common.utility.internal.iterators.CompositeIterator;
18
import org.eclipse.jpt.common.utility.internal.iterators.TransformationIterator;
19
import org.eclipse.jpt.jpa.core.JpaProject;
20
import org.eclipse.jpt.jpa.core.context.Entity;
21
import org.eclipse.jpt.jpa.core.context.PersistentType;
22
import org.eclipse.jpt.jpa.core.context.TypeMapping;
23
import org.eclipse.jpt.jpa.core.context.persistence.ClassRef;
24
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
25
26
/**
27
 * The concrete implementation that is wrapping the design-time representation of a persistence unit.
28
 *
29
 * @version 3.0
30
 * @since 3.0
31
 * @author Pascal Filion
32
 */
33
public final class JpaPersistenceUnit extends JpaManagedTypeProvider {
34
35
	/**
36
	 * Creates a new <code>JpaPersistenceUnit</code>.
37
	 *
38
	 * @param jpaProject The project that gives access to the application's metadata
39
	 * @param persistentUnit The design-time persistence unit
40
	 */
41
	public JpaPersistenceUnit(JpaProject jpaProject, PersistenceUnit persistentUnit) {
42
		super(jpaProject, persistentUnit);
43
	}
44
45
	/**
46
	 * {@inheritDoc}
47
	 */
48
	@Override
49
	JpaEntity buildEntity(TypeMapping mappedClass) {
50
		return new JpaPersistenceUnitEntity(this, (Entity) mappedClass);
51
	}
52
53
	/**
54
	 * {@inheritDoc}
55
	 */
56
	@Override
57
	PersistenceUnit getPersistentTypeContainer() {
58
		return (PersistenceUnit) super.getPersistentTypeContainer();
59
	}
60
61
	@SuppressWarnings("unchecked")
62
	private Iterator<ClassRef> javaClassRefs() {
63
		return new CompositeIterator<ClassRef>(
64
			getPersistentTypeContainer().specifiedClassRefs(),
65
			getPersistentTypeContainer().impliedClassRefs()
66
		);
67
	}
68
69
	/**
70
	 * {@inheritDoc}
71
	 */
72
	@Override
73
	Iterator<? extends PersistentType> persistenceTypes() {
74
		return new TransformationIterator<ClassRef, PersistentType>(javaClassRefs()) {
75
			@Override
76
			protected PersistentType transform(ClassRef classRef) {
77
				return classRef.getJavaPersistentType();
78
			}
79
		};
80
	}
81
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpql/JpaPersistenceUnitEntity.java (+33 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
6
 * 
7
 * Contributors:
8
 *     Oracle - initial API and implementation
9
 *******************************************************************************/
10
package org.eclipse.jpt.jpa.core.internal.jpql;
11
12
import org.eclipse.jpt.jpa.core.context.Entity;
13
14
/**
15
 * The concrete implementation of {@link IEntity} that is wrapping the design-time representation
16
 * of a JPA entity defined in a persistence unit.
17
 *
18
 * @version 3.0
19
 * @since 3.0
20
 * @author Pascal Filion
21
 */
22
final class JpaPersistenceUnitEntity extends JpaEntity {
23
24
	/**
25
	 * Creates a new <code>JpaPersistenceUnitEntity</code>.
26
	 *
27
	 * @param provider The provider of JPA managed types
28
	 * @param entity The design-time model object wrapped by this class
29
	 */
30
	JpaPersistenceUnitEntity(JpaManagedTypeProvider provider, Entity entity) {
31
		super(provider, entity);
32
	}
33
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpql/JpaQuery.java (+115 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the 
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 
5
 * which accompanies this distribution. 
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at 
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.core.internal.jpql;
15
16
import org.eclipse.jpt.common.utility.internal.StringTools;
17
import org.eclipse.jpt.jpa.core.context.NamedQuery;
18
import org.eclipse.persistence.jpa.jpql.spi.IQuery;
19
20
/**
21
 * The concrete implementation of {@link IQuery} that is wrapping the design-time representation
22
 * of a JPQL query.
23
 *
24
 * @version 3.0
25
 * @since 3.0
26
 * @author Pascal Filion
27
 */
28
@SuppressWarnings("nls")
29
public final class JpaQuery implements IQuery {
30
31
	/**
32
	 * The actual JPQL query, which can differ from the one owned by the model object, which happens
33
	 * when the model is out of sync because it has not been updated yet.
34
	 */
35
	private String actualQuery;
36
37
	/**
38
	 *  The provider of managed types.
39
	 */
40
	private JpaManagedTypeProvider provider;
41
42
	/**
43
	 * The model object holding onto the JPQL query.
44
	 */
45
	private NamedQuery query;
46
47
	/**
48
	 * Creates a new <code>JpaQuery</code>.
49
	 *
50
	 * @param provider The provider of managed types
51
	 * @param query The model object of the JPQL query
52
	 */
53
	public JpaQuery(JpaManagedTypeProvider provider, NamedQuery query) {
54
		this(provider, query, query.getQuery());
55
	}
56
57
	/**
58
	 * Creates a new <code>JpaQuery</code>.
59
	 *
60
	 * @param provider The provider of managed types
61
	 * @param query The model object of the JPQL query
62
	 * @param actualQuery The actual JPQL query, which can differ from the one owned by the model
63
	 * object, which happens when the model is out of sync because it has not been updated yet
64
	 */
65
	JpaQuery(JpaManagedTypeProvider provider, NamedQuery query, String actualQuery) {
66
		super();
67
		initialize(provider, query, actualQuery);
68
	}
69
70
	/**
71
	 * {@inheritDoc}
72
	 */
73
	public String getExpression() {
74
		return actualQuery;
75
	}
76
77
	/**
78
	 * {@inheritDoc}
79
	 */
80
	public JpaManagedTypeProvider getProvider() {
81
		return provider;
82
	}
83
84
	/**
85
	 * Returns the encapsulated {@link NamedQuery}, which is the actual object.
86
	 *
87
	 * @return The design-time representation of a JPQL query
88
	 */
89
	NamedQuery getQuery() {
90
		return query;
91
	}
92
93
	private void initialize(JpaManagedTypeProvider provider, NamedQuery query, String actualQuery) {
94
95
		this.query       = query;
96
		this.provider    = provider;
97
		this.actualQuery = actualQuery;
98
99
		if (this.actualQuery == null) {
100
			this.actualQuery = StringTools.EMPTY_STRING;
101
		}
102
	}
103
104
	/**
105
	 * {@inheritDoc}
106
	 */
107
	@Override
108
	public String toString() {
109
		StringBuilder sb = new StringBuilder();
110
		sb.append(super.toString());
111
		sb.append(", query=");
112
		sb.append(getExpression());
113
		return sb.toString();
114
	}
115
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpql/JpaType.java (+430 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
5
 * which accompanies this distribution.
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.core.internal.jpql;
15
16
import java.lang.annotation.Annotation;
17
import java.util.ArrayList;
18
import java.util.Collection;
19
import java.util.Collections;
20
import java.util.List;
21
import org.eclipse.core.runtime.NullProgressMonitor;
22
import org.eclipse.jdt.core.Flags;
23
import org.eclipse.jdt.core.IField;
24
import org.eclipse.jdt.core.IJavaElement;
25
import org.eclipse.jdt.core.IMember;
26
import org.eclipse.jdt.core.IMethod;
27
import org.eclipse.jdt.core.IType;
28
import org.eclipse.jdt.core.ITypeHierarchy;
29
import org.eclipse.jdt.core.dom.AST;
30
import org.eclipse.jdt.core.dom.ASTNode;
31
import org.eclipse.jdt.core.dom.ASTParser;
32
import org.eclipse.jdt.core.dom.AbstractTypeDeclaration;
33
import org.eclipse.jdt.core.dom.AnonymousClassDeclaration;
34
import org.eclipse.jdt.core.dom.ClassInstanceCreation;
35
import org.eclipse.jdt.core.dom.CompilationUnit;
36
import org.eclipse.jdt.core.dom.EnumConstantDeclaration;
37
import org.eclipse.jdt.core.dom.IMethodBinding;
38
import org.eclipse.jdt.core.dom.ITypeBinding;
39
import org.eclipse.jdt.core.dom.NodeFinder;
40
import org.eclipse.jpt.common.core.internal.utility.jdt.ASTTools;
41
import org.eclipse.jpt.common.utility.internal.StringTools;
42
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
43
import org.eclipse.persistence.jpa.jpql.ExpressionTools;
44
import org.eclipse.persistence.jpa.jpql.spi.IConstructor;
45
import org.eclipse.persistence.jpa.jpql.spi.ITypeDeclaration;
46
47
/**
48
 * The concrete implementation of {@link org.eclipse.persistence.jpa.query.spi.IType IType} that is
49
 * wrapping the design-time representation of a Java type.
50
 *
51
 * @version 3.0
52
 * @since 3.0
53
 * @author Pascal Filion
54
 */
55
final class JpaType implements IJpaType {
56
57
	/**
58
	 * The cached collection of {@link IConstructor constructors}.
59
	 */
60
	private Collection<IConstructor> constructors;
61
62
	/**
63
	 * The list of names for the {@link Enum}'s constants otherwise an empty array.
64
	 */
65
	private String[] enumConstants;
66
67
	/**
68
	 * The design-time representation of a Java type.
69
	 */
70
	private IType type;
71
72
	/**
73
	 * The {@link ITypeBinding} for the type, which is the information that was resolved and which
74
	 * can be used to query information about that type.
75
	 */
76
	private ITypeBinding typeBinding;
77
78
	/**
79
	 * This flag makes sure to not try more than once resolving the {@link ITypeBinding} if it fails
80
	 * the first time.
81
	 */
82
	private boolean typeBindingResolved;
83
84
	/**
85
	 * Caches the type hierarchy of the {@link IType} in order to prevent rebuilding it each time.
86
	 */
87
	private ITypeDeclaration typeDeclaration;
88
89
	/**
90
	 * Caches the type hierarchy of the {@link IType} in order to prevent rebuilding it each time
91
	 * {@link #isAssignableTo(org.eclipse.persistence.jpa.query.spi.IType)} is called.
92
	 */
93
	private ITypeHierarchy typeHierarchy;
94
95
	/**
96
	 * The fully qualified name of the Java type.
97
	 */
98
	private final String typeName;
99
100
	/**
101
	 * The external form of a type repository.
102
	 */
103
	private final JpaTypeRepository typeRepository;
104
105
	/**
106
	 * Creates a new <code>JpaType</code>.
107
	 *
108
	 * @param typeRepository The external form of a type repository
109
	 * @param type The design-time representation of a Java type
110
	 */
111
	JpaType(JpaTypeRepository typeRepository, IType type) {
112
		super();
113
		this.type           = type;
114
		this.typeName       = type.getFullyQualifiedName();
115
		this.typeRepository = typeRepository;
116
	}
117
118
	private CompilationUnit buildCompilationUnit() {
119
120
		ASTParser parser = ASTParser.newParser(AST.JLS3);
121
		parser.setSource(type.getTypeRoot());
122
		parser.setIgnoreMethodBodies(true);
123
		parser.setResolveBindings(true);
124
		parser.setBindingsRecovery(true);
125
126
		return (CompilationUnit) parser.createAST(new NullProgressMonitor());
127
	}
128
129
	private Collection<IConstructor> buildConstructors() {
130
131
		ITypeBinding typeBinding = getTypeBinding();
132
133
		// No Java source is attached to the Java class file, parse the class with a reader
134
		if ((typeBinding == null) && type.isBinary()) {
135
			Collection<IConstructor> constructors = new ArrayList<IConstructor>();
136
137
			try {
138
				// Root types
139
				for (IJavaElement rootType : type.getTypeRoot().getChildren()) {
140
					// Root type
141
					if (rootType.getElementType() == IJavaElement.TYPE) {
142
						for (IJavaElement javaElement : ((IType) rootType).getChildren()) {
143
							// Method
144
							if (javaElement.getElementType() == IJavaElement.METHOD) {
145
								IMethod method = (IMethod) javaElement;
146
								// Constructor
147
								if (method.isConstructor()) {
148
									constructors.add(new ClassConstructor(this, method));
149
								}
150
							}
151
						}
152
					}
153
				}
154
			}
155
			catch (Exception e) {
156
				JptJpaCorePlugin.log(e);
157
			}
158
159
			return constructors;
160
		}
161
		// Use the ITypeBinding to retrieve the constructors
162
		else if (typeBinding != null) {
163
			Collection<IConstructor> constructors = new ArrayList<IConstructor>();
164
165
			for (IMethodBinding method : typeBinding.getDeclaredMethods()) {
166
				if (method.isConstructor()) {
167
					constructors.add(new JpaConstructor(this, method));
168
				}
169
			}
170
171
			return constructors;
172
		}
173
174
		return Collections.emptyList();
175
	}
176
177
	private String[] buildEnumConstants() {
178
179
		try {
180
			// Retrieve the enum constants from IType
181
			if (type.isEnum()) {
182
				List<String> names = new ArrayList<String>();
183
184
				for (IField field : type.getFields()) {
185
					if (field.isEnumConstant()) {
186
						names.add(field.getElementName());
187
					}
188
				}
189
190
				return names.toArray(new String[names.size()]);
191
			}
192
		}
193
		catch (Exception e) {
194
			// Just ignore and return an empty array
195
		}
196
197
		return ExpressionTools.EMPTY_STRING_ARRAY;
198
	}
199
200
	private ITypeBinding buildTypeBinding() {
201
202
		// This code was copied from ASTNodes.getTypeBinding(CompilationUnit, IType)
203
		try {
204
			CompilationUnit compilationUnit = buildCompilationUnit();
205
206
			if (type.isAnonymous()) {
207
				IJavaElement parent = type.getParent();
208
209
				if ((parent instanceof IField) && Flags.isEnum(((IMember) parent).getFlags())) {
210
					ASTNode node = NodeFinder.perform(compilationUnit, type.getNameRange());
211
					EnumConstantDeclaration constant = (EnumConstantDeclaration) node;
212
213
					if (constant != null) {
214
						AnonymousClassDeclaration declaration = constant.getAnonymousClassDeclaration();
215
216
						if (declaration != null) {
217
							return declaration.resolveBinding();
218
						}
219
					}
220
				}
221
				else {
222
					ASTNode node = NodeFinder.perform(compilationUnit, type.getNameRange());
223
					ClassInstanceCreation creation = (ClassInstanceCreation) getParent(node, ClassInstanceCreation.class);
224
225
					if (creation != null) {
226
						return creation.resolveTypeBinding();
227
					}
228
				}
229
			}
230
			else {
231
				ASTNode node = NodeFinder.perform(compilationUnit, type.getNameRange());
232
				AbstractTypeDeclaration declaration = (AbstractTypeDeclaration) getParent(node, AbstractTypeDeclaration.class);
233
234
				if (declaration != null) {
235
					return declaration.resolveBinding();
236
				}
237
			}
238
		}
239
		catch (Exception e) {
240
			// Simply ignore
241
		}
242
243
		return null;
244
	}
245
246
	private ITypeDeclaration buildTypeDeclaration() {
247
		return new JpaTypeDeclaration(this, new ITypeDeclaration[0]);
248
	}
249
250
	/**
251
	 * {@inheritDoc}
252
	 */
253
	public Iterable<IConstructor> constructors() {
254
		if (constructors == null) {
255
			constructors = buildConstructors();
256
		}
257
		return constructors;
258
	}
259
260
	/**
261
	 * {@inheritDoc}
262
	 */
263
	@Override
264
	public boolean equals(Object object) {
265
		return (this == object) || equals((org.eclipse.persistence.jpa.jpql.spi.IType) object);
266
	}
267
268
	/**
269
	 * {@inheritDoc}
270
	 */
271
	public boolean equals(org.eclipse.persistence.jpa.jpql.spi.IType type) {
272
		return (this == type) || typeName.equals(type.getName());
273
	}
274
275
	/**
276
	 * {@inheritDoc}
277
	 */
278
	public String[] getEnumConstants() {
279
		if (enumConstants == null) {
280
			enumConstants = buildEnumConstants();
281
		}
282
		return enumConstants;
283
	}
284
285
	/**
286
	 * {@inheritDoc}
287
	 */
288
	public String getName() {
289
		return typeName;
290
	}
291
292
	private ASTNode getParent(ASTNode node, Class<? extends ASTNode> parentClass) {
293
294
		do {
295
			node = node.getParent();
296
		}
297
		while ((node != null) && !parentClass.isInstance(node));
298
299
		return node;
300
	}
301
302
	/**
303
	 * Returns the encapsulated {@link Type}, which is the actual type.
304
	 *
305
	 * @return The design-time representation of a Java type
306
	 */
307
	IType getType() {
308
		return type;
309
	}
310
311
	private ITypeBinding getTypeBinding() {
312
		if ((typeBinding == null) && !typeBindingResolved) {
313
			typeBinding = buildTypeBinding();
314
			typeBindingResolved = true;
315
		}
316
		return typeBinding;
317
	}
318
319
	/**
320
	 * {@inheritDoc}
321
	 */
322
	public ITypeDeclaration getTypeDeclaration() {
323
		if (typeDeclaration == null) {
324
			typeDeclaration = buildTypeDeclaration();
325
		}
326
		return typeDeclaration;
327
	}
328
329
	/**
330
	 * Returns the repository that gives access to the application's classes.
331
	 *
332
	 * @return The external form of the type repository
333
	 */
334
	JpaTypeRepository getTypeRepository() {
335
		return typeRepository;
336
	}
337
338
	/**
339
	 * {@inheritDoc}
340
	 */
341
	public boolean hasAnnotation(Class<? extends Annotation> annotationType) {
342
		return type.getAnnotation(annotationType.getName()) != null;
343
	}
344
345
	/**
346
	 * {@inheritDoc}
347
	 */
348
	@Override
349
	public int hashCode() {
350
		return typeName.hashCode();
351
	}
352
353
	/**
354
	 * {@inheritDoc}
355
	 */
356
	public boolean isAssignableTo(org.eclipse.persistence.jpa.jpql.spi.IType otherType) {
357
358
		if (this == otherType) {
359
			return true;
360
		}
361
362
		String otherTypeName = otherType.getName();
363
364
		// Type hierarchy for Java compiled classes
365
		ITypeBinding typeBinding = getTypeBinding();
366
367
		// Type hierarchy for Class files
368
		if ((typeBinding == null) && type.isBinary()) {
369
370
			// First create the type hierarchy
371
			if (typeHierarchy == null) {
372
				try {
373
					typeHierarchy = type.newSupertypeHierarchy(new NullProgressMonitor());
374
				}
375
				catch (Exception e) {
376
					return false;
377
				}
378
			}
379
380
			// Now check if the other type name is in the type hierarchy
381
			for (IType superType : typeHierarchy.getAllTypes()) {
382
				if (superType.getFullyQualifiedName().equals(otherTypeName)) {
383
					return true;
384
				}
385
			}
386
		}
387
		// Type hierarchy for Java source files
388
		else if (typeBinding != null) {
389
			return ASTTools.typeIsSubTypeOf(typeBinding, otherTypeName);
390
		}
391
392
		// Anything else is always false
393
		return false;
394
	}
395
396
	/**
397
	 * {@inheritDoc}
398
	 */
399
	public boolean isEnum() {
400
		try {
401
			return type.isEnum();
402
		}
403
		catch (Exception e) {
404
			// Simply ignore and return no
405
			return false;
406
		}
407
	}
408
409
	/**
410
	 * {@inheritDoc}
411
	 */
412
	public boolean isResolvable() {
413
		return true;
414
	}
415
416
	/**
417
	 * {@inheritDoc}
418
	 */
419
	public void setTypeDeclaration(JpaTypeDeclaration typeDeclaration) {
420
		this.typeDeclaration = typeDeclaration;
421
	}
422
423
	/**
424
	 * {@inheritDoc}
425
	 */
426
	@Override
427
	public String toString() {
428
		return StringTools.buildToStringFor(this, typeName);
429
	}
430
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpql/JpaTypeDeclaration.java (+105 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
5
 * which accompanies this distribution.
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.core.internal.jpql;
15
16
import org.eclipse.persistence.jpa.jpql.spi.IType;
17
import org.eclipse.persistence.jpa.jpql.spi.ITypeDeclaration;
18
19
/**
20
 * The concrete implementation of {@link ITypeDeclaration} that is wrapping the design-time
21
 * representation of the declaration description of a type.
22
 *
23
 * @version 3.0
24
 * @since 3.0
25
 * @author Pascal Filion
26
 */
27
final class JpaTypeDeclaration implements ITypeDeclaration {
28
29
	/**
30
	 * The dimensionality of the array or 0 if the type is not an array.
31
	 */
32
	private int dimensionality;
33
34
	/**
35
	 * The generics of the given type or an empty list if the type is not parameterized.
36
	 */
37
	private final ITypeDeclaration[] genericTypes;
38
39
	/**
40
	 * The external form of the Java type.
41
	 */
42
	private final IType type;
43
44
	/**
45
	 * Creates a new <code>JpaTypeDeclaration</code>.
46
	 *
47
	 * @param type The external form of the Java type
48
	 * @param genericTypes The generics of the given type or an empty list if the type is not
49
	 * parameterized
50
	 */
51
	JpaTypeDeclaration(IType type, ITypeDeclaration[] genericTypes) {
52
		this(type, genericTypes, 0);
53
	}
54
55
	/**
56
	 * Creates a new <code>JpaTypeDeclaration</code>.
57
	 *
58
	 * @param type The external form of the Java type
59
	 * @param genericTypes The generics of the given type or an empty list if the type is not
60
	 * parameterized
61
	 * @param dimensionality The dimensionality of the array or 0 if it's not an array
62
	 */
63
	JpaTypeDeclaration(IType type, ITypeDeclaration[] genericTypes, int dimensionality) {
64
		super();
65
		this.type           = type;
66
		this.genericTypes   = genericTypes;
67
		this.dimensionality = dimensionality;
68
	}
69
70
	/**
71
	 * {@inheritDoc}
72
	 */
73
	public int getDimensionality() {
74
		return dimensionality;
75
	}
76
77
	/**
78
	 * {@inheritDoc}
79
	 */
80
	public IType getType() {
81
		return type;
82
	}
83
84
	/**
85
	 * {@inheritDoc}
86
	 */
87
	public ITypeDeclaration[] getTypeParameters() {
88
		return genericTypes;
89
	}
90
91
	/**
92
	 * {@inheritDoc}
93
	 */
94
	public boolean isArray() {
95
		return dimensionality > 0;
96
	}
97
98
	/**
99
	 * {@inheritDoc}
100
	 */
101
	@Override
102
	public String toString() {
103
		return type.getName();
104
	}
105
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpql/JpaTypeRepository.java (+404 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
5
 * which accompanies this distribution.
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.core.internal.jpql;
15
16
import java.util.HashMap;
17
import java.util.Map;
18
import org.eclipse.core.resources.IResource;
19
import org.eclipse.core.runtime.IPath;
20
import org.eclipse.jdt.core.IJavaProject;
21
import org.eclipse.jdt.core.IType;
22
import org.eclipse.jdt.core.JavaModelException;
23
import org.eclipse.persistence.jpa.jpql.TypeHelper;
24
import org.eclipse.persistence.jpa.jpql.spi.ITypeDeclaration;
25
import org.eclipse.persistence.jpa.jpql.spi.ITypeRepository;
26
27
/**
28
 * The concrete implementation of {@link ITypeRepository} that is wrapping the design-time
29
 * representation of a type repository.
30
 *
31
 * @version 3.0
32
 * @since 3.0
33
 * @author Pascal Filion
34
 */
35
@SuppressWarnings("nls")
36
final class JpaTypeRepository implements ITypeRepository {
37
38
	/**
39
	 * The Java project that gives access the design-time objects representing the Java types.
40
	 */
41
	private final IJavaProject javaProject;
42
43
	/**
44
	 * Keeps a map of the primitives for fast access.
45
	 */
46
	private Map<String, Class<?>> primitives;
47
48
	/**
49
	 * The cached helper that is using this repository for retrieving {@link IJpaType types}.
50
	 */
51
	private TypeHelper typeHelper;
52
53
	/**
54
	 * The types that have been cached for faster access.
55
	 */
56
	private final Map<String, IJpaType> types;
57
58
	/**
59
	 * The {@link IJpaType} that represents a unresolvable or simply an unknown type, which is created
60
	 * when {@link #getType(String)} is invoked with {@link IJpaType#UNRESOLVABLE_TYPE}.
61
	 */
62
	private IJpaType unresolvableType;
63
64
	/**
65
	 * Creates a new <code>JpaTypeRepository</code>.
66
	 *
67
	 * @param javaProject The Java project that gives access the design-time objects representing
68
	 * the Java types
69
	 */
70
	JpaTypeRepository(IJavaProject javaProject) {
71
		super();
72
		this.javaProject = javaProject;
73
		this.types       = new HashMap<String, IJpaType>();
74
	}
75
76
	private String buildInnerTypeName(String typeName, int index) {
77
		StringBuilder sb = new StringBuilder();
78
		sb.append(typeName.substring(0, index));
79
		sb.append("$");
80
		sb.append(typeName.substring(index + 1, typeName.length()));
81
		return sb.toString();
82
	}
83
84
	private Map<String, Class<?>> buildPrimitives() {
85
		Map<String, Class<?>> primitives = new HashMap<String, Class<?>>();
86
		primitives.put(Byte     .TYPE.getName(), Byte     .TYPE);
87
		primitives.put(Short    .TYPE.getName(), Short    .TYPE);
88
		primitives.put(Character.TYPE.getName(), Character.TYPE);
89
		primitives.put(Integer  .TYPE.getName(), Integer  .TYPE);
90
		primitives.put(Long     .TYPE.getName(), Long     .TYPE);
91
		primitives.put(Float    .TYPE.getName(), Float    .TYPE);
92
		primitives.put(Double   .TYPE.getName(), Double   .TYPE);
93
		primitives.put(Boolean  .TYPE.getName(), Boolean  .TYPE);
94
		return primitives;
95
	}
96
97
	private IJpaType buildType(Class<?> javaType) {
98
		JavaType jpaType = new JavaType(this, javaType);
99
		types.put(jpaType.getName(), jpaType);
100
		return jpaType;
101
	}
102
103
	private IJpaType buildType(IType type) {
104
		JpaType jpaType = new JpaType(this, type);
105
		types.put(jpaType.getName(), jpaType);
106
		return jpaType;
107
	}
108
109
	private IJpaType buildType(String typeName) {
110
		IJpaType jpaType = new SimpleType(this, typeName);
111
		types.put(typeName, jpaType);
112
		return jpaType;
113
	}
114
115
	private String convertToJavaArrayType(String typeName) {
116
117
		int index = typeName.indexOf("[]");
118
		int dimensionality = (typeName.length() - index) / 2;
119
		StringBuilder sb = new StringBuilder();
120
121
		while (dimensionality-- > 0) {
122
			sb.append("[");
123
		}
124
125
		String type = typeName.substring(0, index);
126
		Class<?> primitive = primitives.get(type);
127
128
		if (primitive != null) {
129
			if (primitive == Byte.TYPE) {
130
				sb.append("B");
131
			}
132
			else if (primitive == Character.TYPE) {
133
				sb.append("C");
134
			}
135
			else if (primitive == Short.TYPE) {
136
				sb.append("S");
137
			}
138
			else if (primitive == Integer.TYPE) {
139
				sb.append("I");
140
			}
141
			else if (primitive == Long.TYPE) {
142
				sb.append("L");
143
			}
144
			else if (primitive == Float.TYPE) {
145
				sb.append("F");
146
			}
147
			else if (primitive == Double.TYPE) {
148
				sb.append("D");
149
			}
150
			else if (primitive == Boolean.TYPE) {
151
				sb.append("Z");
152
			}
153
		}
154
		else {
155
			sb.append(type);
156
			sb.append(";");
157
		}
158
159
		return sb.toString();
160
	}
161
162
	private Class<?> findPrimitive(String typeName) {
163
		if (primitives == null) {
164
			primitives = buildPrimitives();
165
		}
166
		return primitives.get(typeName);
167
	}
168
169
	/**
170
	 * Retrieves the design-time Java type for the given type name, which has to be the fully
171
	 * qualified type name.
172
	 *
173
	 * @param typeName The fully qualified type name
174
	 * @return The design-time Java type if it could be retrieved; <code>null</code> otherwise
175
	 */
176
	IType findType(String typeName) {
177
		try {
178
			return javaProject.findType(typeName);
179
		}
180
		catch (JavaModelException e) {
181
			return null;
182
		}
183
	}
184
185
	/**
186
	 * {@inheritDoc}
187
	 */
188
	public IJpaType getEnumType(String enumTypeName) {
189
190
		// Get the position of the last dot so the enum constant can be removed
191
		int lastDotIndex = enumTypeName.lastIndexOf(".");
192
193
		if (lastDotIndex == -1) {
194
			return null;
195
		}
196
197
		// Retrieve the fully qualified enum type name
198
		String typeName = enumTypeName.substring(0, lastDotIndex);
199
200
		// Attempt to load the enum type
201
		IType type = findType(typeName);
202
		IJpaType jpaType;
203
204
		if (type != null) {
205
			jpaType = buildType(type);
206
		}
207
		else {
208
			jpaType = loadInnerType(typeName);
209
		}
210
211
		return (jpaType != null) && jpaType.isEnum() ? jpaType : null;
212
	}
213
214
	/**
215
	 * Returns the Java project, which gives access to the class path.
216
	 *
217
	 * @return The Java project, which gives access to the class path
218
	 */
219
	IJavaProject getJavaProject() {
220
		return javaProject;
221
	}
222
223
	/**
224
	 * {@inheritDoc}
225
	 */
226
	public IJpaType getType(Class<?> javaClass) {
227
		IJpaType type = types.get(javaClass.getName());
228
		if (type == null) {
229
			type = buildType(javaClass);
230
		}
231
		return type;
232
	}
233
234
	/**
235
	 * Retrieves the {@link IType} for the given {@link IResource}.
236
	 *
237
	 * @param resource The workspace location of the {@link IType} to retrieve
238
	 * @return The design-time representation of a Java type
239
	 */
240
	IType getType(IResource resource) {
241
		try {
242
			return (IType) javaProject.findElement((IPath) resource);
243
		}
244
		catch (Exception e) {
245
			return null;
246
		}
247
	}
248
249
	/**
250
	 * {@inheritDoc}
251
	 */
252
	public IJpaType getType(String typeName) {
253
254
		if (IJpaType.UNRESOLVABLE_TYPE == typeName) {
255
			return unresolvableType();
256
		}
257
258
		if (typeName.endsWith("[]")) {
259
			return loadArrayType(typeName);
260
		}
261
262
		if (typeName.charAt(0) == '[') {
263
			return loadJavaArrayType(typeName);
264
		}
265
266
		return loadTypeImp(typeName);
267
	}
268
269
	/**
270
	 * {@inheritDoc}
271
	 */
272
	public TypeHelper getTypeHelper() {
273
		if (typeHelper == null) {
274
			typeHelper = new TypeHelper(this);
275
		}
276
		return typeHelper;
277
	}
278
279
	private IJpaType loadArrayType(String typeName) {
280
281
		IJpaType type = types.get(typeName);
282
283
		if (type == null) {
284
			try {
285
				// Try to see if the type is a JDK class, otherwise, just use the type name
286
				// since IJpaType doesn't support array types
287
				String javaTypeName = convertToJavaArrayType(typeName);
288
				type = buildType(Class.forName(javaTypeName));
289
			}
290
			catch (Exception e) {
291
292
				int index = typeName.indexOf("[]");
293
				int dimensionality = (typeName.length() - index) / 2;
294
295
				type = getType(typeName.substring(0, index));
296
297
				type.setTypeDeclaration(
298
					new JpaTypeDeclaration(type, new ITypeDeclaration[0], dimensionality)
299
				);
300
			}
301
302
			types.put(typeName, type);
303
		}
304
305
		return type;
306
	}
307
308
	private IJpaType loadInnerType(String typeName) {
309
310
		while (true) {
311
312
			int index = typeName.lastIndexOf(".");
313
314
			if (index == -1) {
315
				return null;
316
			}
317
318
			typeName = buildInnerTypeName(typeName, index);
319
			IJpaType cachedType = types.get(typeName);
320
321
			if (cachedType != null) {
322
				return cachedType;
323
			}
324
325
			// Attempt to load the Java type
326
			IType type = findType(typeName);
327
328
			// A Java type exists, return it
329
			if (type != null) {
330
				return buildType(type);
331
			}
332
		}
333
	}
334
335
	private IJpaType loadJavaArrayType(String typeName) {
336
337
		IJpaType type = types.get(typeName);
338
339
		if (type == null) {
340
			try {
341
				// Try to see if the type is a JDK class, otherwise, just use the type name
342
				// since IJpaType doesn't support array types
343
				type = buildType(Class.forName(typeName));
344
			}
345
			catch (Exception e) {
346
347
				int index = typeName.lastIndexOf("[");
348
				int dimensionality = index / 2;
349
350
				type = getType(typeName.substring(index, typeName.endsWith(";") ? typeName.length() - 1 : typeName.length()));
351
352
				type.setTypeDeclaration(
353
					new JpaTypeDeclaration(type, new ITypeDeclaration[0], dimensionality)
354
				);
355
			}
356
357
			types.put(typeName, type);
358
		}
359
360
		return type;
361
	}
362
363
	private IJpaType loadTypeImp(String typeName) {
364
365
		IJpaType type = types.get(typeName);
366
367
		// The type was already cached, simply return it
368
		if (type != null) {
369
			return type;
370
		}
371
372
		// First check for primitive, they don't have a corresponding IJpaType
373
		Class<?> primitive = findPrimitive(typeName);
374
375
		if (primitive != null) {
376
			return buildType(primitive);
377
		}
378
379
		// Attempt to load the Java type
380
		IType iType = findType(typeName);
381
382
		// A Java type exists, return it
383
		if (iType != null) {
384
			return buildType(iType);
385
		}
386
387
		// Now try with a possible inner enum type
388
		type = loadInnerType(typeName);
389
390
		// No Java type exists, create a "null" IJpaType
391
		if (type == null) {
392
			type = buildType(typeName);
393
		}
394
395
		return type;
396
	}
397
398
	private IJpaType unresolvableType() {
399
		if (unresolvableType == null) {
400
			unresolvableType = new SimpleType(this, IJpaType.UNRESOLVABLE_TYPE);
401
		}
402
		return unresolvableType;
403
	}
404
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpql/SimpleType.java (+138 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
5
 * which accompanies this distribution.
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.core.internal.jpql;
15
16
import java.lang.annotation.Annotation;
17
import org.eclipse.jpt.common.utility.internal.StringTools;
18
import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable;
19
import org.eclipse.persistence.jpa.jpql.spi.IConstructor;
20
import org.eclipse.persistence.jpa.jpql.spi.IType;
21
import org.eclipse.persistence.jpa.jpql.spi.ITypeDeclaration;
22
23
/**
24
 * The concrete implementation of {@link IType} that is wrapping the type name only.
25
 *
26
 * @version 3.0
27
 * @since 3.0
28
 * @author Pascal Filion
29
 */
30
final class SimpleType implements IJpaType {
31
32
	/**
33
	 * Caches the type hierarchy of the {@link IType} in order to prevent rebuilding it each time.
34
	 */
35
	private ITypeDeclaration typeDeclaration;
36
37
	/**
38
	 * The fully qualified name of the Java type.
39
	 */
40
	private final String typeName;
41
42
	/**
43
	 * The external form of a type repository.
44
	 */
45
	private final JpaTypeRepository typeRepository;
46
47
	/**
48
	 * Creates a new <code>SimpleType</code>.
49
	 *
50
	 * @param typeName The fully qualified name of the Java type
51
	 */
52
	SimpleType(JpaTypeRepository typeRepository, String typeName) {
53
		super();
54
		this.typeRepository = typeRepository;
55
		this.typeName       = typeName;
56
	}
57
58
	/**
59
	 * {@inheritDoc}
60
	 */
61
	public Iterable<IConstructor> constructors() {
62
		return EmptyIterable.instance();
63
	}
64
65
	/**
66
	 * {@inheritDoc}
67
	 */
68
	public boolean equals(IType type) {
69
		return typeName.equals(type.getName());
70
	}
71
72
	/**
73
	 * {@inheritDoc}
74
	 */
75
	public String[] getEnumConstants() {
76
		return StringTools.EMPTY_STRING_ARRAY;
77
	}
78
79
	/**
80
	 * {@inheritDoc}
81
	 */
82
	public String getName() {
83
		return typeName;
84
	}
85
86
	/**
87
	 * {@inheritDoc}
88
	 */
89
	public ITypeDeclaration getTypeDeclaration() {
90
		if (typeDeclaration == null) {
91
			typeDeclaration = new JpaTypeDeclaration(this, new ITypeDeclaration[0]);
92
		}
93
		return typeDeclaration;
94
	}
95
96
	/**
97
	 * {@inheritDoc}
98
	 */
99
	public boolean hasAnnotation(Class<? extends Annotation> annotationType) {
100
		return false;
101
	}
102
103
	/**
104
	 * {@inheritDoc}
105
	 */
106
	public boolean isAssignableTo(IType type) {
107
		return typeRepository.equals(type.getName());
108
	}
109
110
	/**
111
	 * {@inheritDoc}
112
	 */
113
	public boolean isEnum() {
114
		return false;
115
	}
116
117
	/**
118
	 * {@inheritDoc}
119
	 */
120
	public boolean isResolvable() {
121
		return false;
122
	}
123
124
	/**
125
	 * {@inheritDoc}
126
	 */
127
	public void setTypeDeclaration(JpaTypeDeclaration typeDeclaration) {
128
		this.typeDeclaration = typeDeclaration;
129
	}
130
131
	/**
132
	 * {@inheritDoc}
133
	 */
134
	@Override
135
	public String toString() {
136
		return typeName;
137
	}
138
}
(-)src/org/eclipse/jpt/jpa/core/internal/validation/JpaValidationMessages.java (-7 / +7 lines)
Lines 3-9 Link Here
3
 * This program and the accompanying materials are made available under the
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
6
 * 
6
 *
7
 * Contributors:
7
 * Contributors:
8
 *     Oracle - initial API and implementation
8
 *     Oracle - initial API and implementation
9
 ******************************************************************************/
9
 ******************************************************************************/
Lines 13-19 Link Here
13
public interface JpaValidationMessages {
13
public interface JpaValidationMessages {
14
14
15
	public static final String BUNDLE_NAME = "jpa_validation";
15
	public static final String BUNDLE_NAME = "jpa_validation";
16
	
16
17
	public static final String PROJECT_INVALID_LIBRARY_PROVIDER = "PROJECT_INVALID_LIBRARY_PROVIDER";
17
	public static final String PROJECT_INVALID_LIBRARY_PROVIDER = "PROJECT_INVALID_LIBRARY_PROVIDER";
18
	public static final String PROJECT_NO_CONNECTION = "PROJECT_NO_CONNECTION";
18
	public static final String PROJECT_NO_CONNECTION = "PROJECT_NO_CONNECTION";
19
	public static final String PROJECT_INVALID_CONNECTION = "PROJECT_INVALID_CONNECTION";
19
	public static final String PROJECT_INVALID_CONNECTION = "PROJECT_INVALID_CONNECTION";
Lines 43-48 Link Here
43
	public static final String GENERATOR_NAME_UNDEFINED = "GENERATOR_NAME_UNDEFINED";
43
	public static final String GENERATOR_NAME_UNDEFINED = "GENERATOR_NAME_UNDEFINED";
44
	public static final String QUERY_DUPLICATE_NAME = "QUERY_DUPLICATE_NAME";
44
	public static final String QUERY_DUPLICATE_NAME = "QUERY_DUPLICATE_NAME";
45
	public static final String QUERY_NAME_UNDEFINED = "QUERY_NAME_UNDEFINED";
45
	public static final String QUERY_NAME_UNDEFINED = "QUERY_NAME_UNDEFINED";
46
	public static final String JPQL_QUERY_VALIDATION = "JPQL_QUERY_VALIDATION";
46
	public static final String QUERY_STATEMENT_UNDEFINED = "QUERY_STATEMENT_UNDEFINED";
47
	public static final String QUERY_STATEMENT_UNDEFINED = "QUERY_STATEMENT_UNDEFINED";
47
	public static final String MAPPING_FILE_EXTRANEOUS_PERSISTENCE_UNIT_METADATA = "MAPPING_FILE_EXTRANEOUS_PERSISTENCE_UNIT_METADATA";
48
	public static final String MAPPING_FILE_EXTRANEOUS_PERSISTENCE_UNIT_METADATA = "MAPPING_FILE_EXTRANEOUS_PERSISTENCE_UNIT_METADATA";
48
	public static final String PERSISTENT_TYPE_MAPPED_BUT_NOT_INCLUDED_IN_PERSISTENCE_UNIT = "PERSISTENT_TYPE_MAPPED_BUT_NOT_INCLUDED_IN_PERSISTENCE_UNIT";
49
	public static final String PERSISTENT_TYPE_MAPPED_BUT_NOT_INCLUDED_IN_PERSISTENCE_UNIT = "PERSISTENT_TYPE_MAPPED_BUT_NOT_INCLUDED_IN_PERSISTENCE_UNIT";
Lines 158-164 Link Here
158
	public static final String VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_TABLE_UNRESOLVED_NAME = "VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_TABLE_UNRESOLVED_NAME";
159
	public static final String VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_TABLE_UNRESOLVED_NAME = "VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_TABLE_UNRESOLVED_NAME";
159
	public static final String VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_TABLE_UNRESOLVED_CATALOG = "VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_TABLE_UNRESOLVED_CATALOG";
160
	public static final String VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_TABLE_UNRESOLVED_CATALOG = "VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_TABLE_UNRESOLVED_CATALOG";
160
	public static final String VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_TABLE_UNRESOLVED_SCHEMA = "VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_TABLE_UNRESOLVED_SCHEMA";
161
	public static final String VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_TABLE_UNRESOLVED_SCHEMA = "VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_TABLE_UNRESOLVED_SCHEMA";
161
	
162
162
	public static final String GENERATED_VALUE_UNRESOLVED_GENERATOR = "GENERATED_VALUE_UNRESOLVED_GENERATOR";
163
	public static final String GENERATED_VALUE_UNRESOLVED_GENERATOR = "GENERATED_VALUE_UNRESOLVED_GENERATOR";
163
	public static final String PRIMARY_KEY_JOIN_COLUMN_UNRESOLVED_NAME = "PRIMARY_KEY_JOIN_COLUMN_UNRESOLVED_NAME";
164
	public static final String PRIMARY_KEY_JOIN_COLUMN_UNRESOLVED_NAME = "PRIMARY_KEY_JOIN_COLUMN_UNRESOLVED_NAME";
164
	public static final String PRIMARY_KEY_JOIN_COLUMN_NAME_MUST_BE_SPECIFIED_MULTIPLE_JOIN_COLUMNS = "PRIMARY_KEY_JOIN_COLUMN_NAME_MUST_BE_SPECIFIED_MULTIPLE_JOIN_COLUMNS";
165
	public static final String PRIMARY_KEY_JOIN_COLUMN_NAME_MUST_BE_SPECIFIED_MULTIPLE_JOIN_COLUMNS = "PRIMARY_KEY_JOIN_COLUMN_NAME_MUST_BE_SPECIFIED_MULTIPLE_JOIN_COLUMNS";
Lines 176-182 Link Here
176
	public static final String VIRTUAL_SECONDARY_TABLE_PRIMARY_KEY_JOIN_COLUMN_UNRESOLVED_REFERENCED_COLUMN_NAME = "VIRTUAL_SECONDARY_TABLE_PRIMARY_KEY_JOIN_COLUMN_UNRESOLVED_REFERENCED_COLUMN_NAME";
177
	public static final String VIRTUAL_SECONDARY_TABLE_PRIMARY_KEY_JOIN_COLUMN_UNRESOLVED_REFERENCED_COLUMN_NAME = "VIRTUAL_SECONDARY_TABLE_PRIMARY_KEY_JOIN_COLUMN_UNRESOLVED_REFERENCED_COLUMN_NAME";
177
	public static final String VIRTUAL_SECONDARY_TABLE_PRIMARY_KEY_JOIN_COLUMN_NAME_MUST_BE_SPECIFIED_MULTIPLE_JOIN_COLUMNS = "VIRTUAL_SECONDARY_TABLE_PRIMARY_KEY_JOIN_COLUMN_NAME_MUST_BE_SPECIFIED_MULTIPLE_JOIN_COLUMNS";
178
	public static final String VIRTUAL_SECONDARY_TABLE_PRIMARY_KEY_JOIN_COLUMN_NAME_MUST_BE_SPECIFIED_MULTIPLE_JOIN_COLUMNS = "VIRTUAL_SECONDARY_TABLE_PRIMARY_KEY_JOIN_COLUMN_NAME_MUST_BE_SPECIFIED_MULTIPLE_JOIN_COLUMNS";
178
	public static final String VIRTUAL_SECONDARY_TABLE_PRIMARY_KEY_JOIN_COLUMN_REFERENCED_COLUMN_NAME_MUST_BE_SPECIFIED_MULTIPLE_JOIN_COLUMNS = "VIRTUAL_SECONDARY_TABLE_PRIMARY_KEY_JOIN_COLUMN_REFERENCED_COLUMN_NAME_MUST_BE_SPECIFIED_MULTIPLE_JOIN_COLUMNS";
179
	public static final String VIRTUAL_SECONDARY_TABLE_PRIMARY_KEY_JOIN_COLUMN_REFERENCED_COLUMN_NAME_MUST_BE_SPECIFIED_MULTIPLE_JOIN_COLUMNS = "VIRTUAL_SECONDARY_TABLE_PRIMARY_KEY_JOIN_COLUMN_REFERENCED_COLUMN_NAME_MUST_BE_SPECIFIED_MULTIPLE_JOIN_COLUMNS";
179
	
180
180
	public static final String NO_JPA_PROJECT = "NO_JPA_PROJECT";
181
	public static final String NO_JPA_PROJECT = "NO_JPA_PROJECT";
181
	public static final String TARGET_ENTITY_NOT_DEFINED = "TARGET_ENTITY_NOT_DEFINED";
182
	public static final String TARGET_ENTITY_NOT_DEFINED = "TARGET_ENTITY_NOT_DEFINED";
182
	public static final String VIRTUAL_ATTRIBUTE_TARGET_ENTITY_NOT_DEFINED = "VIRTUAL_ATTRIBUTE_TARGET_ENTITY_NOT_DEFINED";
183
	public static final String VIRTUAL_ATTRIBUTE_TARGET_ENTITY_NOT_DEFINED = "VIRTUAL_ATTRIBUTE_TARGET_ENTITY_NOT_DEFINED";
Lines 186-192 Link Here
186
	public static final String ENTITY_TABLE_PER_CLASS_NOT_SUPPORTED_ON_PLATFORM = "ENTITY_TABLE_PER_CLASS_NOT_SUPPORTED_ON_PLATFORM";
187
	public static final String ENTITY_TABLE_PER_CLASS_NOT_SUPPORTED_ON_PLATFORM = "ENTITY_TABLE_PER_CLASS_NOT_SUPPORTED_ON_PLATFORM";
187
	public static final String ENTITY_TABLE_PER_CLASS_NOT_PORTABLE_ON_PLATFORM = "ENTITY_TABLE_PER_CLASS_NOT_PORTABLE_ON_PLATFORM";
188
	public static final String ENTITY_TABLE_PER_CLASS_NOT_PORTABLE_ON_PLATFORM = "ENTITY_TABLE_PER_CLASS_NOT_PORTABLE_ON_PLATFORM";
188
	public static final String TARGET_NOT_AN_EMBEDDABLE = "TARGET_NOT_AN_EMBEDDABLE";
189
	public static final String TARGET_NOT_AN_EMBEDDABLE = "TARGET_NOT_AN_EMBEDDABLE";
189
	
190
190
	public static final String COLUMN_TABLE_NOT_VALID="COLUMN_TABLE_NOT_VALID";
191
	public static final String COLUMN_TABLE_NOT_VALID="COLUMN_TABLE_NOT_VALID";
191
	public static final String VIRTUAL_ATTRIBUTE_COLUMN_TABLE_NOT_VALID="VIRTUAL_ATTRIBUTE_COLUMN_TABLE_NOT_VALID";
192
	public static final String VIRTUAL_ATTRIBUTE_COLUMN_TABLE_NOT_VALID="VIRTUAL_ATTRIBUTE_COLUMN_TABLE_NOT_VALID";
192
	public static final String VIRTUAL_ATTRIBUTE_OVERRIDE_COLUMN_TABLE_NOT_VALID="VIRTUAL_ATTRIBUTE_OVERRIDE_COLUMN_TABLE_NOT_VALID";
193
	public static final String VIRTUAL_ATTRIBUTE_OVERRIDE_COLUMN_TABLE_NOT_VALID="VIRTUAL_ATTRIBUTE_OVERRIDE_COLUMN_TABLE_NOT_VALID";
Lines 228-232 Link Here
228
	public static final String VIRTUAL_ATTRIBUTE_MAP_KEY_ATTRIBUTE_OVERRIDE_COLUMN_TABLE_NOT_VALID="VIRTUAL_ATTRIBUTE_MAP_KEY_ATTRIBUTE_OVERRIDE_COLUMN_TABLE_NOT_VALID";
229
	public static final String VIRTUAL_ATTRIBUTE_MAP_KEY_ATTRIBUTE_OVERRIDE_COLUMN_TABLE_NOT_VALID="VIRTUAL_ATTRIBUTE_MAP_KEY_ATTRIBUTE_OVERRIDE_COLUMN_TABLE_NOT_VALID";
229
	public static final String MAP_KEY_COLUMN_TABLE_NOT_VALID="MAP_KEY_COLUMN_TABLE_NOT_VALID";
230
	public static final String MAP_KEY_COLUMN_TABLE_NOT_VALID="MAP_KEY_COLUMN_TABLE_NOT_VALID";
230
	public static final String VIRTUAL_ATTRIBUTE_MAP_KEY_COLUMN_TABLE_NOT_VALID="VIRTUAL_ATTRIBUTE_MAP_KEY_COLUMN_TABLE_NOT_VALID";
231
	public static final String VIRTUAL_ATTRIBUTE_MAP_KEY_COLUMN_TABLE_NOT_VALID="VIRTUAL_ATTRIBUTE_MAP_KEY_COLUMN_TABLE_NOT_VALID";
231
232
}
232
}
(-)src/org/eclipse/jpt/jpa/core/resource/orm/XmlNamedNativeQuery.java (-9 / +13 lines)
Lines 3-9 Link Here
3
 * This program and the accompanying materials are made available under the
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
6
 * 
6
 *
7
 * Contributors:
7
 * Contributors:
8
 *     Oracle - initial API and implementation
8
 *     Oracle - initial API and implementation
9
 ******************************************************************************/
9
 ******************************************************************************/
Lines 29-35 Link Here
29
/**
29
/**
30
 * <!-- begin-user-doc -->
30
 * <!-- begin-user-doc -->
31
 * A representation of the model object '<em><b>Named Native Query</b></em>'.
31
 * A representation of the model object '<em><b>Named Native Query</b></em>'.
32
 * 
32
 *
33
 * Provisional API: This interface is part of an interim API that is still
33
 * Provisional API: This interface is part of an interim API that is still
34
 * under development and expected to change significantly before reaching
34
 * under development and expected to change significantly before reaching
35
 * stability. It is available at this early stage to solicit feedback from
35
 * stability. It is available at this early stage to solicit feedback from
Lines 538-548 Link Here
538
		result.append(')');
538
		result.append(')');
539
		return result.toString();
539
		return result.toString();
540
	}
540
	}
541
	
541
542
	public TextRange getNameTextRange() {
542
	public TextRange getNameTextRange() {
543
		return getAttributeTextRange(JPA.NAME);
543
		return getAttributeTextRange(JPA.NAME);
544
	}
544
	}
545
	
545
546
	public TextRange getQueryTextRange() {
547
		return getAttributeTextRange(JPA.QUERY);
548
	}
549
546
	// ********** translators **********
550
	// ********** translators **********
547
551
548
	public static Translator buildTranslator(String elementName, EStructuralFeature structuralFeature) {
552
	public static Translator buildTranslator(String elementName, EStructuralFeature structuralFeature) {
Lines 563-585 Link Here
563
	protected static Translator buildNameTranslator() {
567
	protected static Translator buildNameTranslator() {
564
		return new Translator(JPA.NAME, OrmPackage.eINSTANCE.getXmlQuery_Name(), Translator.DOM_ATTRIBUTE);
568
		return new Translator(JPA.NAME, OrmPackage.eINSTANCE.getXmlQuery_Name(), Translator.DOM_ATTRIBUTE);
565
	}
569
	}
566
	
570
567
	protected static Translator buildResultClassTranslator() {
571
	protected static Translator buildResultClassTranslator() {
568
		return new Translator(JPA.RESULT_CLASS, OrmPackage.eINSTANCE.getXmlNamedNativeQuery_ResultClass(), Translator.DOM_ATTRIBUTE);
572
		return new Translator(JPA.RESULT_CLASS, OrmPackage.eINSTANCE.getXmlNamedNativeQuery_ResultClass(), Translator.DOM_ATTRIBUTE);
569
	}
573
	}
570
	
574
571
	protected static Translator buildResultSetMappingTranslator() {
575
	protected static Translator buildResultSetMappingTranslator() {
572
		return new Translator(JPA.RESULT_SET_MAPPING, OrmPackage.eINSTANCE.getXmlNamedNativeQuery_ResultSetMapping(), Translator.DOM_ATTRIBUTE);
576
		return new Translator(JPA.RESULT_SET_MAPPING, OrmPackage.eINSTANCE.getXmlNamedNativeQuery_ResultSetMapping(), Translator.DOM_ATTRIBUTE);
573
	}
577
	}
574
	
578
575
	protected static Translator buildDescriptionTranslator() {
579
	protected static Translator buildDescriptionTranslator() {
576
		return new Translator(JPA2_0.DESCRIPTION, OrmV2_0Package.eINSTANCE.getXmlQuery_2_0_Description());
580
		return new Translator(JPA2_0.DESCRIPTION, OrmV2_0Package.eINSTANCE.getXmlQuery_2_0_Description());
577
	}
581
	}
578
	
582
579
	protected static Translator buildQueryTranslator() {
583
	protected static Translator buildQueryTranslator() {
580
		return new Translator(JPA.QUERY, OrmPackage.eINSTANCE.getXmlQuery_Query());
584
		return new Translator(JPA.QUERY, OrmPackage.eINSTANCE.getXmlQuery_Query());
581
	}
585
	}
582
	
586
583
	protected static Translator buildHintTranslator() {
587
	protected static Translator buildHintTranslator() {
584
		return XmlQueryHint.buildTranslator(JPA.HINT, OrmPackage.eINSTANCE.getXmlQuery_Hints());
588
		return XmlQueryHint.buildTranslator(JPA.HINT, OrmPackage.eINSTANCE.getXmlQuery_Hints());
585
	}
589
	}
(-)src/org/eclipse/jpt/jpa/core/resource/orm/XmlNamedQuery.java (-7 / +29 lines)
Lines 3-9 Link Here
3
 * This program and the accompanying materials are made available under the
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
6
 * 
6
 *
7
 * Contributors:
7
 * Contributors:
8
 *     Oracle - initial API and implementation
8
 *     Oracle - initial API and implementation
9
 ******************************************************************************/
9
 ******************************************************************************/
Lines 19-24 Link Here
19
import org.eclipse.emf.ecore.impl.ENotificationImpl;
19
import org.eclipse.emf.ecore.impl.ENotificationImpl;
20
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
20
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
21
import org.eclipse.emf.ecore.util.InternalEList;
21
import org.eclipse.emf.ecore.util.InternalEList;
22
import org.eclipse.jpt.common.core.internal.utility.SimpleTextRange;
22
import org.eclipse.jpt.common.core.internal.utility.translators.SimpleTranslator;
23
import org.eclipse.jpt.common.core.internal.utility.translators.SimpleTranslator;
23
import org.eclipse.jpt.common.core.utility.TextRange;
24
import org.eclipse.jpt.common.core.utility.TextRange;
24
import org.eclipse.jpt.jpa.core.resource.orm.v2_0.JPA2_0;
25
import org.eclipse.jpt.jpa.core.resource.orm.v2_0.JPA2_0;
Lines 27-37 Link Here
27
import org.eclipse.jpt.jpa.core.resource.orm.v2_0.XmlNamedQuery_2_0;
28
import org.eclipse.jpt.jpa.core.resource.orm.v2_0.XmlNamedQuery_2_0;
28
import org.eclipse.jpt.jpa.core.resource.xml.AbstractJpaEObject;
29
import org.eclipse.jpt.jpa.core.resource.xml.AbstractJpaEObject;
29
import org.eclipse.wst.common.internal.emf.resource.Translator;
30
import org.eclipse.wst.common.internal.emf.resource.Translator;
31
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
30
32
31
/**
33
/**
32
 * <!-- begin-user-doc -->
34
 * <!-- begin-user-doc -->
33
 * A representation of the model object '<em><b>Named Query</b></em>'.
35
 * A representation of the model object '<em><b>Named Query</b></em>'.
34
 * 
36
 *
35
 * Provisional API: This interface is part of an interim API that is still
37
 * Provisional API: This interface is part of an interim API that is still
36
 * under development and expected to change significantly before reaching
38
 * under development and expected to change significantly before reaching
37
 * stability. It is available at this early stage to solicit feedback from
39
 * stability. It is available at this early stage to solicit feedback from
Lines 503-513 Link Here
503
		result.append(')');
505
		result.append(')');
504
		return result.toString();
506
		return result.toString();
505
	}
507
	}
506
	
508
507
	public TextRange getNameTextRange() {
509
	public TextRange getNameTextRange() {
508
		return getAttributeTextRange(JPA.NAME);
510
		return getAttributeTextRange(JPA.NAME);
509
	}
511
	}
510
	
512
513
	public TextRange getQueryTextRange() {
514
		// <named-query>
515
		IDOMNode node = getElementNode(JPA.QUERY);
516
		if (node != null) {
517
			// The query element has text
518
			if (node.hasChildNodes()) {
519
				return buildTextRange((IDOMNode) node.getFirstChild());
520
			}
521
			// The query element does not have text
522
			TextRange textRange = buildTextRange(node);
523
			return new SimpleTextRange(
524
				node.getEndStructuredDocumentRegion().getStartOffset(),
525
				0,
526
				textRange.getLineNumber()
527
			);
528
		}
529
530
		return this.getValidationTextRange();
531
	}
532
511
	// ********** translators **********
533
	// ********** translators **********
512
534
513
	public static Translator buildTranslator(String elementName, EStructuralFeature structuralFeature) {
535
	public static Translator buildTranslator(String elementName, EStructuralFeature structuralFeature) {
Lines 527-541 Link Here
527
	protected static Translator buildNameTranslator() {
549
	protected static Translator buildNameTranslator() {
528
		return new Translator(JPA.NAME, OrmPackage.eINSTANCE.getXmlQuery_Name(), Translator.DOM_ATTRIBUTE);
550
		return new Translator(JPA.NAME, OrmPackage.eINSTANCE.getXmlQuery_Name(), Translator.DOM_ATTRIBUTE);
529
	}
551
	}
530
	
552
531
	protected static Translator buildDescriptionTranslator() {
553
	protected static Translator buildDescriptionTranslator() {
532
		return new Translator(JPA2_0.DESCRIPTION, OrmV2_0Package.eINSTANCE.getXmlQuery_2_0_Description());
554
		return new Translator(JPA2_0.DESCRIPTION, OrmV2_0Package.eINSTANCE.getXmlQuery_2_0_Description());
533
	}
555
	}
534
	
556
535
	protected static Translator buildQueryTranslator() {
557
	protected static Translator buildQueryTranslator() {
536
		return new Translator(JPA.QUERY, OrmPackage.eINSTANCE.getXmlQuery_Query());
558
		return new Translator(JPA.QUERY, OrmPackage.eINSTANCE.getXmlQuery_Query());
537
	}
559
	}
538
	
560
539
	protected static Translator buildLockModeTranslator() {
561
	protected static Translator buildLockModeTranslator() {
540
		return new Translator(JPA2_0.NAMED_QUERY__LOCK_MODE, OrmV2_0Package.eINSTANCE.getXmlNamedQuery_2_0_LockMode());
562
		return new Translator(JPA2_0.NAMED_QUERY__LOCK_MODE, OrmV2_0Package.eINSTANCE.getXmlNamedQuery_2_0_LockMode());
541
	}
563
	}
(-)src/org/eclipse/jpt/jpa/core/resource/orm/XmlQuery.java (-4 / +6 lines)
Lines 3-9 Link Here
3
 * This program and the accompanying materials are made available under the
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
6
 * 
6
 *
7
 * Contributors:
7
 * Contributors:
8
 *     Oracle - initial API and implementation
8
 *     Oracle - initial API and implementation
9
 ******************************************************************************/
9
 ******************************************************************************/
Lines 16-22 Link Here
16
/**
16
/**
17
 * <!-- begin-user-doc -->
17
 * <!-- begin-user-doc -->
18
 * A representation of the model object '<em><b>Query</b></em>'.
18
 * A representation of the model object '<em><b>Query</b></em>'.
19
 * 
19
 *
20
 * Provisional API: This interface is part of an interim API that is still
20
 * Provisional API: This interface is part of an interim API that is still
21
 * under development and expected to change significantly before reaching
21
 * under development and expected to change significantly before reaching
22
 * stability. It is available at this early stage to solicit feedback from
22
 * stability. It is available at this early stage to solicit feedback from
Lines 106-111 Link Here
106
	 * @generated
106
	 * @generated
107
	 */
107
	 */
108
	EList<XmlQueryHint> getHints();
108
	EList<XmlQueryHint> getHints();
109
	
109
110
	public TextRange getNameTextRange();
110
	TextRange getNameTextRange();
111
112
	TextRange getQueryTextRange();
111
}
113
}
(-)META-INF/MANIFEST.MF (+3 lines)
Lines 32-37 Link Here
32
 org.eclipse.jst.common.project.facet.ui;bundle-version="[1.3.100,2.0.0)",
32
 org.eclipse.jst.common.project.facet.ui;bundle-version="[1.3.100,2.0.0)",
33
 org.eclipse.jst.j2ee;bundle-version="[1.1.200,2.0.0)",
33
 org.eclipse.jst.j2ee;bundle-version="[1.1.200,2.0.0)",
34
 org.eclipse.jst.j2ee.ui;bundle-version="[1.1.200,2.0.0)",
34
 org.eclipse.jst.j2ee.ui;bundle-version="[1.1.200,2.0.0)",
35
 org.eclipse.persistence.jpa.jpql;bundle-version="1.0.0",
35
 org.eclipse.ui.ide;bundle-version="[3.4.0,4.0.0)",
36
 org.eclipse.ui.ide;bundle-version="[3.4.0,4.0.0)",
36
 org.eclipse.ui.views.properties.tabbed;bundle-version="[3.4.0,4.0.0)",
37
 org.eclipse.ui.views.properties.tabbed;bundle-version="[3.4.0,4.0.0)",
37
 org.eclipse.ui.navigator;bundle-version="[3.3.100,4.0.0)",
38
 org.eclipse.ui.navigator;bundle-version="[3.3.100,4.0.0)",
Lines 41-46 Link Here
41
 org.eclipse.wst.common.frameworks.ui;bundle-version="[1.1.200,2.0.0)",
42
 org.eclipse.wst.common.frameworks.ui;bundle-version="[1.1.200,2.0.0)",
42
 org.eclipse.wst.common.project.facet.ui;bundle-version="[1.3.0,2.0.0)",
43
 org.eclipse.wst.common.project.facet.ui;bundle-version="[1.3.0,2.0.0)",
43
 org.eclipse.wst.sse.ui;bundle-version="[1.1.0,2.0.0)",
44
 org.eclipse.wst.sse.ui;bundle-version="[1.1.0,2.0.0)",
45
 org.eclipse.wst.validation;bundle-version="1.2.300",
44
 org.eclipse.wst.web.ui;bundle-version="[1.1.200,2.0.0)"
46
 org.eclipse.wst.web.ui;bundle-version="[1.1.200,2.0.0)"
45
Export-Package: org.eclipse.jpt.jpa.ui,
47
Export-Package: org.eclipse.jpt.jpa.ui,
46
 org.eclipse.jpt.jpa.ui.details,
48
 org.eclipse.jpt.jpa.ui.details,
Lines 64-69 Link Here
64
 org.eclipse.jpt.jpa.ui.internal.jpa2.persistence.connection;x-internal:=true,
66
 org.eclipse.jpt.jpa.ui.internal.jpa2.persistence.connection;x-internal:=true,
65
 org.eclipse.jpt.jpa.ui.internal.jpa2.persistence.options;x-internal:=true,
67
 org.eclipse.jpt.jpa.ui.internal.jpa2.persistence.options;x-internal:=true,
66
 org.eclipse.jpt.jpa.ui.internal.jpa2.platform.generic;x-internal:=true,
68
 org.eclipse.jpt.jpa.ui.internal.jpa2.platform.generic;x-internal:=true,
69
 org.eclipse.jpt.jpa.ui.internal.jpql;x-internal:=true,
67
 org.eclipse.jpt.jpa.ui.internal.listeners;x-internal:=true,
70
 org.eclipse.jpt.jpa.ui.internal.listeners;x-internal:=true,
68
 org.eclipse.jpt.jpa.ui.internal.menus;x-internal:=true,
71
 org.eclipse.jpt.jpa.ui.internal.menus;x-internal:=true,
69
 org.eclipse.jpt.jpa.ui.internal.navigator;x-internal:=true,
72
 org.eclipse.jpt.jpa.ui.internal.navigator;x-internal:=true,
(-)plugin.xml (-7 / +50 lines)
Lines 1-7 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
1
<?xml version="1.0" encoding="UTF-8"?>
2
<?eclipse version="3.2"?>
2
<?eclipse version="3.2"?>
3
<!--
3
<!--
4
  Copyright (c) 2007, 2010 Oracle. All rights reserved.
4
  Copyright (c) 2007, 2011 Oracle. All rights reserved.
5
  This program and the accompanying materials are made available under the
5
  This program and the accompanying materials are made available under the
6
  terms of the Eclipse Public License v1.0, which accompanies this distribution
6
  terms of the Eclipse Public License v1.0, which accompanies this distribution
7
  and is available at http://www.eclipse.org/legal/epl-v10.html.
7
  and is available at http://www.eclipse.org/legal/epl-v10.html.
Lines 69-78 Link Here
69
			<partition type="__dftl_partition_content_type"/>
69
			<partition type="__dftl_partition_content_type"/>
70
			<partition type="__java_string"/>
70
			<partition type="__java_string"/>
71
		</javaCompletionProposalComputer>
71
		</javaCompletionProposalComputer>
72
		
72
73
	</extension>
73
	</extension>
74
	
74
75
	
76
	<extension
75
	<extension
77
		point="org.eclipse.jdt.ui.javaCompletionProposalComputer"
76
		point="org.eclipse.jdt.ui.javaCompletionProposalComputer"
78
		id="jpaProposalCategory"
77
		id="jpaProposalCategory"
Lines 80-87 Link Here
80
		<proposalCategory
79
		<proposalCategory
81
			icon="$nl$/icons/full/eview16/jpa_perspective.gif"/>
80
			icon="$nl$/icons/full/eview16/jpa_perspective.gif"/>
82
	</extension>
81
	</extension>
83
	
82
84
	
83
	<extension
84
		point="org.eclipse.jdt.ui.javaCompletionProposalComputer"
85
		id="JpaJpqlCompletionProposalComputer">
86
87
		<javaCompletionProposalComputer
88
        activate="true"
89
        categoryId="org.eclipse.jpt.jpa.ui.jpaProposalCategory"
90
        class="org.eclipse.jpt.jpa.ui.internal.jpql.JpaJpqlJavaCompletionProposalComputer">
91
			<partition type="__dftl_partition_content_type"/>
92
			<partition type="__java_string"/>
93
		</javaCompletionProposalComputer>
94
		
95
	</extension>
96
97
	 <extension
98
	       id="JpaJpqlSseCompletionProposal"
99
	       point="org.eclipse.wst.sse.ui.completionProposal">
100
	    <proposalComputer
101
	          activate="true"
102
	          categoryId="org.eclipse.wst.xml.ui.proposalCategory.xmlTags"
103
	          class="org.eclipse.jpt.jpa.ui.internal.jpql.JpaJpqlSseCompletionProposalComputer"
104
	          id="org.eclipse.jpt.jpa.ui.internal.jpql.JpaJpqlSseCompletionProposalComputer">
105
	       <contentType
106
	             id="org.eclipse.jpt.jpa.core.content.mappingFile">
107
	       </contentType>
108
	    </proposalComputer>
109
	    <proposalComputer
110
	          activate="true"
111
	          categoryId="org.eclipse.wst.xml.ui.proposalCategory.xmlTags"
112
	          class="org.eclipse.jpt.jpa.ui.internal.jpql.JpaJpqlSseCompletionProposalComputer"
113
	          id="org.eclipse.jpt.jpa.ui.internal.jpql.JpaJpqlSseCompletionProposalComputer">
114
	       <contentType
115
	             id="org.eclipse.jpt.jpa.eclipselink.core.content.orm">
116
	       </contentType>
117
	    </proposalComputer>
118
	 </extension>	
119
120
85
	<extension
121
	<extension
86
		point="org.eclipse.jpt.jpa.ui.jpaPlatformUis">
122
		point="org.eclipse.jpt.jpa.ui.jpaPlatformUis">
87
		
123
		
Lines 94-100 Link Here
94
			id="generic2_0.ui"
130
			id="generic2_0.ui"
95
			jpaPlatform="generic2_0"
131
			jpaPlatform="generic2_0"
96
			factoryClass="org.eclipse.jpt.jpa.ui.internal.jpa2.platform.generic.Generic2_0JpaPlatformUiFactory"/>
132
			factoryClass="org.eclipse.jpt.jpa.ui.internal.jpa2.platform.generic.Generic2_0JpaPlatformUiFactory"/>
97
		
133
	
98
	</extension>
134
	</extension>
99
  	
135
  	
100
	
136
	
Lines 1035-1039 Link Here
1035
		</wizard-pages>
1071
		</wizard-pages>
1036
		
1072
		
1037
	</extension>
1073
	</extension>
1074
 <extension
1075
       id="org.eclipse.jpt.jpa.ui"
1076
       point="org.eclipse.core.runtime.preferences">
1077
    <initializer
1078
          class="org.eclipse.jpt.jpa.ui.internal.prefs.JpaUiPreferenceInitializer">
1079
    </initializer>
1080
 </extension>
1038
 	
1081
 	
1039
</plugin>
1082
</plugin>
(-)property_files/jpt_ui.properties (-1 / +10 lines)
Lines 118-124 Link Here
118
JpaMakePersistentWizardPage_mappingFileDoesNotExistError=The XML mapping file does not exist
118
JpaMakePersistentWizardPage_mappingFileDoesNotExistError=The XML mapping file does not exist
119
JpaMakePersistentWizardPage_mappingFileNotListedInPersistenceXmlError=The XML mapping file is not listed in the persistence.xml
119
JpaMakePersistentWizardPage_mappingFileNotListedInPersistenceXmlError=The XML mapping file is not listed in the persistence.xml
120
120
121
JpaPreferencesPage_Description=Expand the tree to edit preferences for a particular JPA feature.
121
JpaPreferencesPage_description=General settings for JPA development:
122
JpaPreferencesPage_jpqlEditor=JPQL Editing
123
JpaPreferencesPage_jpqlEditor_description=Specify the case for JPQL identifiers used with content assist.
124
JpaPreferencesPage_jpqlEditor_lowerCaseRadioButton=&Lowercase
125
JpaPreferencesPage_jpqlEditor_matchFirstCharacterCaseRadioButton=&Match Case of First Character
126
JpaPreferencesPage_jpqlEditor_upperCaseRadioButton=&Uppercase
122
127
123
JpaProblemSeveritiesPage_Description=Select the severity level for the following optional Java Persistence validation problems:
128
JpaProblemSeveritiesPage_Description=Select the severity level for the following optional Java Persistence validation problems:
124
JpaProblemSeveritiesPage_Error=Error
129
JpaProblemSeveritiesPage_Error=Error
Lines 126-131 Link Here
126
JpaProblemSeveritiesPage_Info=Info
131
JpaProblemSeveritiesPage_Info=Info
127
JpaProblemSeveritiesPage_Warning=Warning
132
JpaProblemSeveritiesPage_Warning=Warning
128
133
134
JpqlContentProposalProvider_Description=Content Assist Available ({0})
135
JpaJpqlJavaCompletionProposalComputer_Error=Can't retrieve JPQL proposals due to an internal error.
136
JpaJpqlSseCompletionProposalComputer_Error=Can't retrieve JPQL proposals due to an internal error.
137
129
MappingFileWizard_title=New Mapping File
138
MappingFileWizard_title=New Mapping File
130
MappingFileWizardPage_newFile_title=Mapping file
139
MappingFileWizardPage_newFile_title=Mapping file
131
MappingFileWizardPage_newFile_desc=Specify mapping file name and location
140
MappingFileWizardPage_newFile_desc=Specify mapping file name and location
(-)property_files/jpt_ui_jpql_identifiers.properties (+83 lines)
Added Link Here
1
################################################################################
2
# Copyright (c) 2011 Oracle. All rights reserved.
3
# This program and the accompanying materials are made available under the
4
# terms of the Eclipse Public License v1.0, which accompanies this distribution
5
# and is available at http://www.eclipse.org/legal/epl-v10.html.
6
# 
7
# Contributors:
8
#     Oracle - initial API and implementation
9
################################################################################
10
11
# JPA 1.0 identifiers
12
ABS=The <b>ABS</b> function removes the minus sign from a specified numeric argument and returns the absolute value (integer, float, or double) of the same type as the argument to the function, which is always a positive number or zero.
13
ALL=<ul><li>An <b>ALL</b> conditional expression is a predicate that is <code>true</code> if the comparison operation is <code>true</code> for all values in the result of the subquery or the result of the subquery is empty.</li><li>An <b>ALL</b> conditional expression is <code>false</code> if the result of the comparison is <code>false</code> for at least one row, and is unknown if neither <code>true</code> nor <code>false</code>.</ul><p><p>The comparison operators used with <b>ALL</b> conditional expressions are =, <, <=, >, >=, <>.<p><p>The result of the subquery must be like that of the other argument to the comparison operator in type.
14
#AND
15
ANY=<ul><li>An <b>ANY</b> conditional expression is a predicate that is <code>true</code> if the comparison operation is <code>true</code> for some value in the result of the subquery.</li><li>An <b>ANY</b> conditional expression is <code>false</code> if the result of the subquery is empty or if the comparison operation is <code>false</code> for every value in the result of the subquery,</li><li>and is unknown if neither <code>true</code> nor <code>false</code>.</li></ul><p><p>The comparison operators used with <b>ANY</b> conditional expressions are =, <, <=, >, >=, <>.<p><p>The result of the subquery must be like that of the other argument to the comparison operator in type.
16
ASC=The keyword <b>ASC</b> specifies that ascending ordering be used for the associated order by item.
17
AVG=One of the aggregate functions. The arguments must be numeric. <b>AVG</b> returns <code>Double</code>.<p><p><b>BNF:</b> <code>expression ::= AVG([DISTINCT] state_field_path_expression)</code>
18
BETWEEN=Used in conditional expression to determine whether the result of an expression falls within an inclusive range of values. Numeric, string and date expression can be evaluated in this way.
19
BOTH=Trim from both ends.
20
CONCAT=The <b>CONCAT</b> function returns a string that is a concatenation of its arguments.
21
COUNT=One of the aggregate functions. The return type of this function is a <code>Long</code>.
22
CURRENT_DATE=This function returns the value of current date on the database server.
23
CURRENT_TIME=This function returns the value of current time on the database server.
24
CURRENT_TIMESTAMP=This function returns the value of current timestamp on the database
25
DELETE_FROM=A delete statement provide bulk operations over sets of entities.
26
DESC=The keyword <b>DESC</b> specifies that descending ordering be used. Ascending ordering is the default.
27
DISTINCT=The <b>DISTINCT</b> keyword is used to specify that duplicate values must be eliminated from the query result. If <b>DISTINCT</b> is not specified, duplicate values are not eliminated.
28
ESCAPE=The optional <code>escape character</code> is a single-character string literal or a character-valued input parameter (i.e., char or Character) and is used to escape the special meaning of the underscore and percent characters in <code>pattern value</code>.
29
EXISTS=An <b>EXISTS</b> expression is a predicate that is <code>true</code> only if the result of the subquery consists of one or more values and that is <code>false</code> otherwise.
30
FROM=The <b>FROM</b> clause of a query defines the domain of the query by declaring identification variables. An identification variable is an identifier declared in the <b>FROM</b> clause of a query. The domain of the query may be constrained by path expressions. Identification variables designate instances of a particular entity abstract schema type. The <b>FROM</b> clause can contain multiple identification variable declarations separated by a comma (,).
31
GROUP_BY=The <b>GROUP BY</b> construct enables the aggregation of values according to the properties of an entity class.
32
HAVING=The <b>HAVING</b> construct enables conditions to be specified that further restrict the query result as restrictions upon the groups.
33
IN=An identification variable declared by a collection member declaration ranges over values of a collection obtained by navigation using a path expression. Such a path expression represents a navigation involving the association-fields of an entity abstract schema type. Because a path expression can be based on another path expression, the navigation can use the association-fields of related entities. An identification variable of a collection member declaration is declared using a special operator, the reserved identifier <b>IN</b>. The argument to the <b>IN</b> operator is a collection-valued path expression. The path expression evaluates to a collection type specified as a result of navigation to a collection-valued association-field of an entity abstract schema type.
34
IS_EMPTY=An <b>EMPTY</b> expression tests whether or not the collection designated by the collection-valued path expression is empty (i.e, has no elements).
35
IS_NULL=A null comparison tests whether or not the single-valued path expression or input parameter is a <b>NULL</b> value.
36
JOIN=A <b>JOIN</b> enables the fetching of an association as a side effect of the execution of a query. A <b>JOIN</b> is specified over an entity and its related entities.
37
JOIN_FETCH=A <b>JOIN FETCH</b> enables the fetching of an association as a side effect of the execution of a query. A <b>JOIN FETCH</b> is specified over an entity and its related entities.
38
LEADING=Trim from leading end.
39
LENGTH=The <b>LENGTH</b> function returns the length of the string in characters as an integer.
40
LIKE=The <b>LIKE</b> condition is used to specify a search for a pattern.<p><p>The <code>string_expression</code> must have a string value. The <code>pattern_value</code> is a string literal or a string-valued input parameter in which an underscore (_) stands for any single character, a percent (%) character stands for any sequence of characters (including the empty sequence), and all other characters stand for themselves. The optional <code>escape_character</code> is a single-character string literal or a character-valued input parameter (i.e., char or Character) and is used to escape the special meaning of the underscore and percent characters in <code>pattern_value</code>.
41
LOCATE=The <b>LOCATE</b> function returns the position of a given string within a string, starting the search at a specified position. It returns the first position at which the string was found as an integer. The first argument is the string to be located; the second argument is the string to be searched; the optional third argument is an integer that represents the string position at which the search is started (by default, the beginning of the string to be searched). The first position in a string is denoted by 1. If the string is not found, 0 is returned. The <b>LENGTH</b> function returns the length of the string in characters as an integer.
42
LOWER=The <b>LOWER</b> function converts a string to lower case and it returns a string.
43
MAX=One of the aggregate functions. The arguments must correspond to orderable state-field types (i.e., numeric types, string types, character types, or date types). The return type of this function is based on the state-field's type.
44
MEMBER=This expression tests whether the designated value is a member of the collection specified by the collection-valued path expression. If the collection-valued path expression designates an empty collection, the value of the <b>MEMBER OF</b> expression is <b>FALSE</b> and the value of the <b>NOT MEMBER OF</b> expression is <b>TRUE</b>. Otherwise, if the value of the collection-valued path expression or single-valued association-field path expression in the collection member expression is <b>NULL</b> or unknown, the value of the collection member expression is unknown.
45
MIN= One of the aggregate functions. The arguments must correspond to orderable state-field types (i.e., numeric types, string types, character types, or date types). The return type of this function is based on the state-field's type.
46
MOD=The modulo operation finds the remainder of division of one number by another. It takes two integer arguments and returns an integer.
47
NEW=In the <b>SELECT</b> clause a constructor may be used in the <b>SELECT</b> list to return one or more Java instances. The specified class is not required to be an entity or to be mapped to the database. The constructor name must be fully qualified.
48
OBJECT=Stand-alone identification variables in the <b>SELECT</b> clause may optionally be qualified by the <b>OBJECT</b> operator. The <b>SELECT</b> clause must not use the <b>OBJECT</b> operator to qualify path expressions.
49
#OR
50
ORDER_BY=The <b>ORDER BY</b> clause allows the objects or values that are returned by the query to be ordered.
51
SELECT=The <b>SELECT</b> clause determines the type of the objects or values to be selected.
52
SIZE=The <b>SIZE</b> function returns an integer value, the number of elements of the collection. If the collection is empty, the <b>SIZE</b> function evaluates to zero.
53
SOME=<ul><li>An <b>SOME</b> conditional expression is a predicate that is <code>true</code> if the comparison operation is <code>true</code> for some value in the result of the subquery.</li><li>A <b>SOME</b> conditional expression is <code>false</code> if the result of the subquery is empty or if the comparison operation is <code>false</code> for every value in the result of the subquery,</li><li>and is unknown if neither <code>true</code> nor <code>false</code>.</li></ul><p><p>The comparison operators used with <b>SOME</b> conditional expressions are =, <, <=, >, >=, <>.<p><p>The result of the subquery must be like that of the other argument to the comparison operator in type.
54
SQRT=The <b>SQRT</b> function takes a numeric argument and returns a double.
55
SUBSTRING=The second and third arguments of the <b>SUBSTRING</b> function denote the starting position and length of the substring to be returned. These arguments are integers. The first position of a string is denoted by 1. The <b>SUBSTRING</b> function returns a string.
56
SUM= One of the aggregate functions. The arguments must be numeric. The <b>SUM</b> function returns <code>Long</code> when applied to state-fields of integral types (other than <code>BigInteger</code>); <code>Double</code> when applied to state-fields of floating point types; <code>BigInteger</code> when applied to state-fields of type <code>BigInteger</code>; and <code>BigDecimal</code> when applied to state-fields of type <code>BigDecimal</code>. If <b>SUM</b>, <b>AVG</b>, <b>MAX</b>, or <b>MIN</b> is used, and there are no values to which the aggregate function can be applied, the result of the aggregate function is <code>NULL</code>. If <code>COUNT</code> is used, and there are no values to which <b>COUNT</b> can be applied, the result of the aggregate function is 0.
57
TRAILING=Trim from trailing end.
58
TRIM=The <b>TRIM</b> function trims the specified character from a string. If the character to be trimmed is not specified, it is assumed to be space (or blank). The optional <code>trim_character</code> is a single-character string literal or a character-valued input parameter (i.e., char or Character). If a trim specification is not provided, <b>BOTH</b> is assumed. The <b>TRIM</b> function returns the trimmed string.
59
UPDATE=An update statement provide bulk operations over sets of entities.
60
UPPER=The <b>UPPER</b> function converts a string to upper case and it returns a string.
61
WHERE=The <b>WHERE</b> clause of a query consists of a conditional expression used to select objects or values that satisfy the expression. The <b>WHERE</b> clause restricts the result of a select statement or the scope of an update or delete operation.
62
63
# JPA 2.0 identifiers
64
CASE=A <b>CASE</b> expression can include any number of any number of <b>WHEN/THEN</b> statement pairs and returns one of the values in the map or the default item, evaluating the map key expressions to decide which.
65
COALESCE=A <b>COALESCE</b> expression returns <code>null</code> if all its arguments evaluate to <code>null</code>, and the value of the first non-<code>null</code> argument otherwise.<p><p>The return type is the type returned by the arguments if they are all of the same type, otherwise it is undetermined.
66
ENTRY=Use <b>ENTRY</b> in the <b>FROM</b> clause of a <b>MAP</b>. 
67
INDEX=The <b>INDEX</b> function returns an integer value corresponding to the position of its argument in an ordered list. The <b>INDEX</b> function can only be applied to identification variables denoting types for which an order column has been specified.
68
KEY=Use <b>KEY</b> in the <b>SELECT</b> clause or the <b>WHERE</b> clause of a <b>MAP</b>. 
69
NULLIF=<b>NULLIF</b> returns the first expression if the two expressions are not equal. If the expressions are equal, <b>NULLIF</b> returns a null value of the type of the first expression.<p><p><b>NULLIF</b> is equivalent to a searched <b>CASE</b> expression in which the two expressions are equal and the resulting expression is <b>NULL</b>.<p><p>Returns the same type as the first expression.
70
TYPE=An entity type expression can be used to restrict query polymorphism. The <b>TYPE</b> operator returns the exact type of the argument.
71
VALUE=Use <b>VALUE</b> in the <b>SELECT</b> clause or the <b>WHERE</b> clause of a <b>MAP</b>. 
72
73
# EclipseLink identifiers
74
FUNC=Use <b>FUNC</b> for direct, native database functions.
75
TREAT=<b>TREAT</b> downcasts child classes in inheritance hierarchy.
76
77
# Reserved JPQL identifiers
78
BIT_LENGTH=The identifier <b>BIT_LENGTH</b> is not currently used: it is reserved for future use.
79
CHAR_LENGTH=The identifier <b>CHAR_LENGTH</b> is not currently used: it is reserved for future use.
80
CHARACTER_LENGTH=The identifier <b>CHARACTER_LENGTH</b> is not currently used: it is reserved for future use.
81
CLASS=The identifier <b>CLASS</b> is not currently used: it is reserved for future use.
82
POSITION=The identifier <b>POSITION</b> is not currently used: it is reserved for future use.
83
UNKNOWN=The identifier <b>UNKNOWN</b> is not currently used: it is reserved for future use.
(-)property_files/jpt_ui_validation_preferences.properties (+1 lines)
Lines 209-211 Link Here
209
ID_MAPPING_UNRESOLVED_GENERATOR_NAME=Unresolved generator name:
209
ID_MAPPING_UNRESOLVED_GENERATOR_NAME=Unresolved generator name:
210
GENERATED_VALUE_UNRESOLVED_GENERATOR=Generator is not defined in the persistence unit:
210
GENERATED_VALUE_UNRESOLVED_GENERATOR=Generator is not defined in the persistence unit:
211
QUERY_DUPLICATE_NAME=Duplicate query defined:
211
QUERY_DUPLICATE_NAME=Duplicate query defined:
212
JPQL_QUERY_VALIDATION=Invalid or incomplete JPQL queries:
(-)src/org/eclipse/jpt/jpa/ui/JptJpaUiPlugin.java (-3 / +14 lines)
Lines 54-59 Link Here
54
	private static final Object FOCUS_DATA = new Object();
54
	private static final Object FOCUS_DATA = new Object();
55
55
56
56
57
	// ********** Preference keys **********
58
59
	/**
60
	 * The preference key used to retrieve the case used for JPQL identifiers.
61
	 */
62
	public static final String JPQL_IDENTIFIER_CASE_PREF_KEY = PLUGIN_ID + ".jpqlIdentifier.case";
63
	public static final String JPQL_IDENTIFIER_LOWERCASE_PREF_VALUE = "lowercase";
64
	public static final String JPQL_IDENTIFIER_UPPERCASE_PREF_VALUE = "uppercase";
65
	public static final String JPQL_IDENTIFIER_MATCH_FIRST_CHARACTER_CASE_PREF_KEY = PLUGIN_ID + ".jpqlIdentifier.matchFirstCharacterCase";
66
67
57
	// ********** singleton **********
68
	// ********** singleton **********
58
69
59
	private static JptJpaUiPlugin INSTANCE;
70
	private static JptJpaUiPlugin INSTANCE;
Lines 117-125 Link Here
117
	 * Return an image for the specified <code>.gif<code>
128
	 * Return an image for the specified <code>.gif<code>
118
	 * file in the icons folder.
129
	 * file in the icons folder.
119
	 */
130
	 */
120
	//TODO we are using the ImageRegistry here and storing all our icons for the life of the plugin, 
131
	//TODO we are using the ImageRegistry here and storing all our icons for the life of the plugin,
121
	//which means until the workspace is closed.  This is better than before where we constantly 
132
	//which means until the workspace is closed.  This is better than before where we constantly
122
	//created new images. Bug 306437 is about cleaning this up and using Local Resource Managers 
133
	//created new images. Bug 306437 is about cleaning this up and using Local Resource Managers
123
	//on our views so that closing the JPA perspective would mean our icons are disposed.
134
	//on our views so that closing the JPA perspective would mean our icons are disposed.
124
	public static Image getImage(String key) {
135
	public static Image getImage(String key) {
125
		ImageRegistry imageRegistry = instance().getImageRegistry();
136
		ImageRegistry imageRegistry = instance().getImageRegistry();
(-)src/org/eclipse/jpt/jpa/ui/internal/JptUiIcons.java (-1 / +10 lines)
Lines 124-127 Link Here
124
	public static final String TRANSIENT = "full/obj16/transient";
124
	public static final String TRANSIENT = "full/obj16/transient";
125
	
125
	
126
	public static final String NULL_ATTRIBUTE_MAPPING = "full/obj16/null-attribute-mapping";
126
	public static final String NULL_ATTRIBUTE_MAPPING = "full/obj16/null-attribute-mapping";
127
}
127
128
129
	// **************** Content Assist icons **********************************
130
131
	public static final String JPQL_FUNCTION = "full/obj16/jpql.function";
132
133
	public static final String JPQL_IDENTIFIER = "full/obj16/jpql.identifier";
134
135
	public static final String JPQL_VARIABLE = "full/obj16/jpql.variable";
136
}
(-)src/org/eclipse/jpt/jpa/ui/internal/JptUiMessages.java (-4 / +11 lines)
Lines 92-97 Link Here
92
	public static String JpaFacetWizardPage_title;
92
	public static String JpaFacetWizardPage_title;
93
	public static String JpaFacetWizardPage_userLibsLink;
93
	public static String JpaFacetWizardPage_userLibsLink;
94
	public static String JpaFacetWizardPage_userServerLibLabel;
94
	public static String JpaFacetWizardPage_userServerLibLabel;
95
	public static String JpaJpqlJavaCompletionProposalComputer_Error;
96
	public static String JpaJpqlSseCompletionProposalComputer_Error;
95
	public static String JpaLibraryProviderInstallPanel_includeLibraries;
97
	public static String JpaLibraryProviderInstallPanel_includeLibraries;
96
	public static String JpaMakePersistentWizardPage_title;
98
	public static String JpaMakePersistentWizardPage_title;
97
	public static String JpaMakePersistentWizardPage_message;
99
	public static String JpaMakePersistentWizardPage_message;
Lines 110-115 Link Here
110
	public static String JpaStructureView_linkWithEditorTooltip;
112
	public static String JpaStructureView_linkWithEditorTooltip;
111
	public static String JpaStructureView_structureNotAvailable;
113
	public static String JpaStructureView_structureNotAvailable;
112
	public static String JpaStructureView_numItemsSelected;
114
	public static String JpaStructureView_numItemsSelected;
115
	public static String JpqlContentProposalProvider_Description;
113
	public static String MappingFileWizard_title;
116
	public static String MappingFileWizard_title;
114
	public static String MappingFileWizardPage_newFile_title;
117
	public static String MappingFileWizardPage_newFile_title;
115
	public static String MappingFileWizardPage_newFile_desc;
118
	public static String MappingFileWizardPage_newFile_desc;
Lines 132-138 Link Here
132
	public static String OverwriteConfirmerDialog_title;
135
	public static String OverwriteConfirmerDialog_title;
133
	public static String PersistenceItemLabelProviderFactory_persistenceLabel;
136
	public static String PersistenceItemLabelProviderFactory_persistenceLabel;
134
	public static String EntitiesGenerator_jobName;
137
	public static String EntitiesGenerator_jobName;
135
	public static String JpaPreferencesPage_Description;
138
	public static String JpaPreferencesPage_description;
139
	public static String JpaPreferencesPage_jpqlEditor;
140
	public static String JpaPreferencesPage_jpqlEditor_description;
141
	public static String JpaPreferencesPage_jpqlEditor_lowerCaseRadioButton;
142
	public static String JpaPreferencesPage_jpqlEditor_matchFirstCharacterCaseRadioButton;
143
	public static String JpaPreferencesPage_jpqlEditor_upperCaseRadioButton;
136
	public static String JpaProblemSeveritiesPage_Description;
144
	public static String JpaProblemSeveritiesPage_Description;
137
	public static String JpaProblemSeveritiesPage_Error;
145
	public static String JpaProblemSeveritiesPage_Error;
138
	public static String JpaProblemSeveritiesPage_Ignore;
146
	public static String JpaProblemSeveritiesPage_Ignore;
Lines 140-146 Link Here
140
	public static String JpaProblemSeveritiesPage_Warning;
148
	public static String JpaProblemSeveritiesPage_Warning;
141
	public static String SelectJpaOrmMappingFileDialog_newButton;
149
	public static String SelectJpaOrmMappingFileDialog_newButton;
142
150
143
	
151
144
	private static final String BUNDLE_NAME = "jpt_ui"; //$NON-NLS-1$
152
	private static final String BUNDLE_NAME = "jpt_ui"; //$NON-NLS-1$
145
	private static final Class<?> BUNDLE_CLASS = JptUiMessages.class;
153
	private static final Class<?> BUNDLE_CLASS = JptUiMessages.class;
146
	static {
154
	static {
Lines 150-154 Link Here
150
	private JptUiMessages() {
158
	private JptUiMessages() {
151
		throw new UnsupportedOperationException();
159
		throw new UnsupportedOperationException();
152
	}
160
	}
153
161
}
154
}
(-)src/org/eclipse/jpt/jpa/ui/internal/JptUiValidationPreferenceMessages.java (-12 / +11 lines)
Lines 1-9 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2009, 2010 Oracle. All rights reserved.
2
 * Copyright (c) 2009, 2011 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
6
 * 
6
 *
7
 * Contributors:
7
 * Contributors:
8
 *     Oracle - initial API and implementation
8
 *     Oracle - initial API and implementation
9
 ******************************************************************************/
9
 ******************************************************************************/
Lines 19-27 Link Here
19
	public static String PROJECT_INVALID_CONNECTION;
19
	public static String PROJECT_INVALID_CONNECTION;
20
	public static String PROJECT_INACTIVE_CONNECTION;
20
	public static String PROJECT_INACTIVE_CONNECTION;
21
	public static String PROJECT_NO_PERSISTENCE_XML;
21
	public static String PROJECT_NO_PERSISTENCE_XML;
22
	
22
23
	public static String XML_VERSION_NOT_LATEST;
23
	public static String XML_VERSION_NOT_LATEST;
24
	
24
25
	public static String PROJECT_MULTIPLE_PERSISTENCE_XML;
25
	public static String PROJECT_MULTIPLE_PERSISTENCE_XML;
26
	public static String PERSISTENCE_NO_PERSISTENCE_UNIT;
26
	public static String PERSISTENCE_NO_PERSISTENCE_UNIT;
27
	public static String PERSISTENCE_MULTIPLE_PERSISTENCE_UNITS;
27
	public static String PERSISTENCE_MULTIPLE_PERSISTENCE_UNITS;
Lines 82-94 Link Here
82
	public static String ELEMENT_COLLECTION_TARGET_CLASS_NOT_DEFINED;
82
	public static String ELEMENT_COLLECTION_TARGET_CLASS_NOT_DEFINED;
83
	public static String ELEMENT_COLLECTION_TARGET_CLASS_MUST_BE_EMBEDDABLE_OR_BASIC_TYPE;
83
	public static String ELEMENT_COLLECTION_TARGET_CLASS_MUST_BE_EMBEDDABLE_OR_BASIC_TYPE;
84
	public static String ELEMENT_COLLECTION_MAP_KEY_CLASS_NOT_DEFINED;
84
	public static String ELEMENT_COLLECTION_MAP_KEY_CLASS_NOT_DEFINED;
85
	
85
86
	public static String DATABASE_CATEGORY;
86
	public static String DATABASE_CATEGORY;
87
	public static String TABLE_CATEGORY;
87
	public static String TABLE_CATEGORY;
88
	public static String COLUMN_CATEGORY;
88
	public static String COLUMN_CATEGORY;
89
	public static String OVERRIDES_CATEGORY;
89
	public static String OVERRIDES_CATEGORY;
90
	public static String IMPLIED_ATTRIBUTE_LEVEL_CATEGORY;
90
	public static String IMPLIED_ATTRIBUTE_LEVEL_CATEGORY;
91
	
91
92
	public static String TABLE_UNRESOLVED_CATALOG;
92
	public static String TABLE_UNRESOLVED_CATALOG;
93
	public static String TABLE_UNRESOLVED_SCHEMA;
93
	public static String TABLE_UNRESOLVED_SCHEMA;
94
	public static String TABLE_UNRESOLVED_NAME;
94
	public static String TABLE_UNRESOLVED_NAME;
Lines 125-136 Link Here
125
	public static String VIRTUAL_SECONDARY_TABLE_PRIMARY_KEY_JOIN_COLUMN_REFERENCED_COLUMN_NAME_MUST_BE_SPECIFIED_MULTIPLE_JOIN_COLUMNS;
125
	public static String VIRTUAL_SECONDARY_TABLE_PRIMARY_KEY_JOIN_COLUMN_REFERENCED_COLUMN_NAME_MUST_BE_SPECIFIED_MULTIPLE_JOIN_COLUMNS;
126
	public static String MAP_KEY_COLUMN_TABLE_NOT_VALID;
126
	public static String MAP_KEY_COLUMN_TABLE_NOT_VALID;
127
	public static String VIRTUAL_MAP_KEY_ATTRIBUTE_OVERRIDE_COLUMN_TABLE_NOT_VALID;
127
	public static String VIRTUAL_MAP_KEY_ATTRIBUTE_OVERRIDE_COLUMN_TABLE_NOT_VALID;
128
	
128
129
	public static String COLLECTION_TABLE_UNRESOLVED_CATALOG;
129
	public static String COLLECTION_TABLE_UNRESOLVED_CATALOG;
130
	public static String COLLECTION_TABLE_UNRESOLVED_SCHEMA;
130
	public static String COLLECTION_TABLE_UNRESOLVED_SCHEMA;
131
	public static String COLLECTION_TABLE_UNRESOLVED_NAME;
131
	public static String COLLECTION_TABLE_UNRESOLVED_NAME;
132
	public static String ORDER_COLUMN_UNRESOLVED_NAME;
132
	public static String ORDER_COLUMN_UNRESOLVED_NAME;
133
	
133
134
	public static String VIRTUAL_ATTRIBUTE_JOIN_TABLE_UNRESOLVED_CATALOG;
134
	public static String VIRTUAL_ATTRIBUTE_JOIN_TABLE_UNRESOLVED_CATALOG;
135
	public static String VIRTUAL_ATTRIBUTE_JOIN_TABLE_UNRESOLVED_SCHEMA;
135
	public static String VIRTUAL_ATTRIBUTE_JOIN_TABLE_UNRESOLVED_SCHEMA;
136
	public static String VIRTUAL_ATTRIBUTE_JOIN_TABLE_UNRESOLVED_NAME;
136
	public static String VIRTUAL_ATTRIBUTE_JOIN_TABLE_UNRESOLVED_NAME;
Lines 170-176 Link Here
170
	public static String VIRTUAL_ATTRIBUTE_INVERSE_JOIN_COLUMN_REFERENCED_COLUMN_NAME_MUST_BE_SPECIFIED_MULTIPLE_JOIN_COLUMNS;
170
	public static String VIRTUAL_ATTRIBUTE_INVERSE_JOIN_COLUMN_REFERENCED_COLUMN_NAME_MUST_BE_SPECIFIED_MULTIPLE_JOIN_COLUMNS;
171
	public static String VIRTUAL_ATTRIBUTE_MAP_KEY_COLUMN_TABLE_NOT_VALID;
171
	public static String VIRTUAL_ATTRIBUTE_MAP_KEY_COLUMN_TABLE_NOT_VALID;
172
	public static String VIRTUAL_ATTRIBUTE_MAP_KEY_ATTRIBUTE_OVERRIDE_COLUMN_TABLE_NOT_VALID;
172
	public static String VIRTUAL_ATTRIBUTE_MAP_KEY_ATTRIBUTE_OVERRIDE_COLUMN_TABLE_NOT_VALID;
173
	
173
174
	public static String VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_TABLE_UNRESOLVED_CATALOG;
174
	public static String VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_TABLE_UNRESOLVED_CATALOG;
175
	public static String VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_TABLE_UNRESOLVED_SCHEMA;
175
	public static String VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_TABLE_UNRESOLVED_SCHEMA;
176
	public static String VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_TABLE_UNRESOLVED_NAME;
176
	public static String VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_TABLE_UNRESOLVED_NAME;
Lines 205-210 Link Here
205
	public static String ID_MAPPING_UNRESOLVED_GENERATOR_NAME;
205
	public static String ID_MAPPING_UNRESOLVED_GENERATOR_NAME;
206
	public static String GENERATED_VALUE_UNRESOLVED_GENERATOR;
206
	public static String GENERATED_VALUE_UNRESOLVED_GENERATOR;
207
	public static String QUERY_DUPLICATE_NAME;
207
	public static String QUERY_DUPLICATE_NAME;
208
	public static String JPQL_QUERY_VALIDATION;
208
209
209
	private static final String BUNDLE_NAME = "jpt_ui_validation_preferences"; //$NON-NLS-1$
210
	private static final String BUNDLE_NAME = "jpt_ui_validation_preferences"; //$NON-NLS-1$
210
	private static final Class<?> BUNDLE_CLASS = JptUiValidationPreferenceMessages.class;
211
	private static final Class<?> BUNDLE_CLASS = JptUiValidationPreferenceMessages.class;
Lines 215-220 Link Here
215
	private JptUiValidationPreferenceMessages() {
216
	private JptUiValidationPreferenceMessages() {
216
		throw new UnsupportedOperationException();
217
		throw new UnsupportedOperationException();
217
	}
218
	}
218
219
}
219
220
}
(-)src/org/eclipse/jpt/jpa/ui/internal/details/NamedQueryPropertyComposite.java (-31 / +52 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2009 Oracle. All rights reserved.
2
 * Copyright (c) 2008, 2011 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
Lines 15-24 Link Here
15
import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel;
15
import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel;
16
import org.eclipse.jpt.jpa.core.context.NamedQuery;
16
import org.eclipse.jpt.jpa.core.context.NamedQuery;
17
import org.eclipse.jpt.jpa.core.context.Query;
17
import org.eclipse.jpt.jpa.core.context.Query;
18
import org.eclipse.jpt.jpa.ui.internal.jpql.JpaJpqlContentProposalProvider;
18
import org.eclipse.swt.widgets.Composite;
19
import org.eclipse.swt.widgets.Composite;
19
20
20
/**
21
/**
21
 * Here the layout of this pane:
22
 * Here's the layout of this pane:
22
 * <pre>
23
 * <pre>
23
 * -----------------------------------------------------------------------------
24
 * -----------------------------------------------------------------------------
24
 * |        ------------------------------------------------------------------ |
25
 * |        ------------------------------------------------------------------ |
Lines 40-50 Link Here
40
 * @see NamedQueriesComposite - The parent container
41
 * @see NamedQueriesComposite - The parent container
41
 * @see QueryHintsComposite
42
 * @see QueryHintsComposite
42
 *
43
 *
43
 * @version 2.0
44
 * @version 2.3
44
 * @since 2.0
45
 * @since 2.3
45
 */
46
 */
46
public class NamedQueryPropertyComposite<T extends NamedQuery> extends Pane<T>
47
public class NamedQueryPropertyComposite<T extends NamedQuery> extends Pane<T> {
47
{
48
48
	/**
49
	/**
49
	 * Creates a new <code>NamedQueryPropertyComposite</code>.
50
	 * Creates a new <code>NamedQueryPropertyComposite</code>.
50
	 *
51
	 *
Lines 59-64 Link Here
59
		super(parentPane, subjectHolder, parent);
60
		super(parentPane, subjectHolder, parent);
60
	}
61
	}
61
62
63
	protected WritablePropertyValueModel<String> buildNameTextHolder() {
64
		return new PropertyAspectAdapter<NamedQuery, String>(
65
				getSubjectHolder(), Query.NAME_PROPERTY) {
66
			@Override
67
			protected String buildValue_() {
68
				return this.subject.getName();
69
			}
70
71
			@Override
72
			protected void setValue_(String value) {
73
				if (value.length() == 0) {
74
					value = null;
75
				}
76
				this.subject.setName(value);
77
			}
78
		};
79
	}
80
62
	protected WritablePropertyValueModel<String> buildQueryHolder() {
81
	protected WritablePropertyValueModel<String> buildQueryHolder() {
63
		return new PropertyAspectAdapter<NamedQuery, String>(getSubjectHolder(), Query.QUERY_PROPERTY) {
82
		return new PropertyAspectAdapter<NamedQuery, String>(getSubjectHolder(), Query.QUERY_PROPERTY) {
64
			@Override
83
			@Override
Lines 73-119 Link Here
73
		};
92
		};
74
	}
93
	}
75
94
95
	/**
96
	 * {@inheritDoc}
97
	 */
76
	@Override
98
	@Override
77
	protected void initializeLayout(Composite container) {
99
	protected void initializeLayout(Composite container) {
78
		
100
101
		// Name widgets
79
		addLabeledText(
102
		addLabeledText(
80
			container, 
103
			container,
81
			JptUiDetailsMessages.NamedQueryComposite_nameTextLabel, 
104
			JptUiDetailsMessages.NamedQueryComposite_nameTextLabel,
82
			buildNameTextHolder());
105
			buildNameTextHolder());
83
106
107
		JpaJpqlContentProposalProvider provider = new JpaJpqlContentProposalProvider(
108
			container,
109
			getSubjectHolder(),
110
			buildQueryHolder()
111
		);
112
84
		// Query text area
113
		// Query text area
85
		addLabeledMultiLineText(
114
		Composite queryWidgets = this.addLabeledComposite(
86
			container,
115
			container,
87
			JptUiDetailsMessages.NamedQueryPropertyComposite_query,
116
			JptUiDetailsMessages.NamedQueryPropertyComposite_query,
88
			buildQueryHolder(),
117
			provider.getStyledText()
118
		);
119
120
		// Install the content assist icon at the top left of the StyledText.
121
		// Note: For some reason, this needs to be done after the StyledText
122
		//       is added to the labeled composite
123
		provider.installControlDecoration();
124
125
		adjustMultiLineTextLayout(
126
			queryWidgets,
89
			4,
127
			4,
90
			null
128
			provider.getStyledText(),
129
			provider.getStyledText().getLineHeight()
91
		);
130
		);
92
131
93
		// Query Hints pane
132
		// Query Hints pane
94
		container = addTitledGroup(
133
		container = this.addTitledGroup(
95
			addSubPane(container, 5),
134
			addSubPane(container, 5),
96
			JptUiDetailsMessages.NamedQueryPropertyComposite_queryHintsGroupBox
135
			JptUiDetailsMessages.NamedQueryPropertyComposite_queryHintsGroupBox
97
		);
136
		);
98
137
99
		new QueryHintsComposite(this, container);
138
		new QueryHintsComposite(this, container);
100
	}
139
	}
101
		
102
	protected WritablePropertyValueModel<String> buildNameTextHolder() {
103
		return new PropertyAspectAdapter<NamedQuery, String>(
104
				getSubjectHolder(), Query.NAME_PROPERTY) {
105
			@Override
106
			protected String buildValue_() {
107
				return this.subject.getName();
108
			}
109
		
110
			@Override
111
			protected void setValue_(String value) {
112
				if (value.length() == 0) {
113
					value = null;
114
				}
115
				this.subject.setName(value);
116
			}
117
		};
118
	}
119
}
140
}
(-)src/org/eclipse/jpt/jpa/ui/internal/details/QueriesComposite.java (-3 / +3 lines)
Lines 17-24 Link Here
17
import org.eclipse.jface.window.Window;
17
import org.eclipse.jface.window.Window;
18
import org.eclipse.jpt.common.ui.internal.util.ControlSwitcher;
18
import org.eclipse.jpt.common.ui.internal.util.ControlSwitcher;
19
import org.eclipse.jpt.common.ui.internal.widgets.AddRemoveListPane;
19
import org.eclipse.jpt.common.ui.internal.widgets.AddRemoveListPane;
20
import org.eclipse.jpt.common.ui.internal.widgets.Pane;
21
import org.eclipse.jpt.common.ui.internal.widgets.AddRemovePane.Adapter;
20
import org.eclipse.jpt.common.ui.internal.widgets.AddRemovePane.Adapter;
21
import org.eclipse.jpt.common.ui.internal.widgets.Pane;
22
import org.eclipse.jpt.common.utility.internal.CollectionTools;
22
import org.eclipse.jpt.common.utility.internal.CollectionTools;
23
import org.eclipse.jpt.common.utility.internal.Transformer;
23
import org.eclipse.jpt.common.utility.internal.Transformer;
24
import org.eclipse.jpt.common.utility.internal.model.value.CompositeListValueModel;
24
import org.eclipse.jpt.common.utility.internal.model.value.CompositeListValueModel;
Lines 75-81 Link Here
75
{
75
{
76
	private AddRemoveListPane<QueryContainer> listPane;
76
	private AddRemoveListPane<QueryContainer> listPane;
77
	NamedNativeQueryPropertyComposite namedNativeQueryPane;
77
	NamedNativeQueryPropertyComposite namedNativeQueryPane;
78
	NamedQueryPropertyComposite<? extends NamedQuery> namedQueryPane;
78
	Pane<? extends NamedQuery> namedQueryPane;
79
	private WritablePropertyValueModel<Query> queryHolder;
79
	private WritablePropertyValueModel<Query> queryHolder;
80
80
81
81
Lines 295-301 Link Here
295
		installPaneSwitcher(pageBook);
295
		installPaneSwitcher(pageBook);
296
	}
296
	}
297
	
297
	
298
	protected NamedQueryPropertyComposite<? extends NamedQuery> buildNamedQueryPropertyComposite(PageBook pageBook) {
298
	protected Pane<? extends NamedQuery> buildNamedQueryPropertyComposite(PageBook pageBook) {
299
		return new NamedQueryPropertyComposite<NamedQuery>(
299
		return new NamedQueryPropertyComposite<NamedQuery>(
300
			this,
300
			this,
301
			this.buildNamedQueryHolder(),
301
			this.buildNamedQueryHolder(),
(-)src/org/eclipse/jpt/jpa/ui/internal/jpa2/details/NamedQueryProperty2_0Composite.java (-17 / +98 lines)
Lines 1-27 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
* Copyright (c) 2009 Oracle. All rights reserved.
2
* Copyright (c) 2009, 2011 Oracle. All rights reserved.
3
* This program and the accompanying materials are made available under the
3
* This program and the accompanying materials are made available under the
4
* terms of the Eclipse Public License v1.0, which accompanies this distribution
4
* terms of the Eclipse Public License v1.0, which accompanies this distribution
5
* and is available at http://www.eclipse.org/legal/epl-v10.html.
5
* and is available at http://www.eclipse.org/legal/epl-v10.html.
6
* 
6
*
7
* Contributors:
7
* Contributors:
8
*     Oracle - initial API and implementation
8
*     Oracle - initial API and implementation
9
*******************************************************************************/
9
*******************************************************************************/
10
package org.eclipse.jpt.jpa.ui.internal.jpa2.details;
10
package org.eclipse.jpt.jpa.ui.internal.jpa2.details;
11
11
12
import org.eclipse.jpt.common.ui.internal.widgets.Pane;
12
import org.eclipse.jpt.common.ui.internal.widgets.Pane;
13
import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
13
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
14
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
15
import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel;
16
import org.eclipse.jpt.jpa.core.context.Query;
14
import org.eclipse.jpt.jpa.core.jpa2.context.NamedQuery2_0;
17
import org.eclipse.jpt.jpa.core.jpa2.context.NamedQuery2_0;
15
import org.eclipse.jpt.jpa.ui.internal.details.JptUiDetailsMessages;
18
import org.eclipse.jpt.jpa.ui.internal.details.JptUiDetailsMessages;
16
import org.eclipse.jpt.jpa.ui.internal.details.NamedQueryPropertyComposite;
17
import org.eclipse.jpt.jpa.ui.internal.details.QueryHintsComposite;
19
import org.eclipse.jpt.jpa.ui.internal.details.QueryHintsComposite;
20
import org.eclipse.jpt.jpa.ui.internal.jpql.JpaJpqlContentProposalProvider;
18
import org.eclipse.swt.widgets.Composite;
21
import org.eclipse.swt.widgets.Composite;
19
22
20
/**
23
/**
21
 *  NamedQueryProperty2_0Composite
24
 * Here's the layout of this pane:
25
 * <pre>
26
 * -----------------------------------------------------------------------------
27
 * |            -------------------------------------------------------------- |
28
 * | Query:     | I                                                          | |
29
 * |            |                                                            | |
30
 * |            |                                                            | |
31
 * |            -------------------------------------------------------------- |
32
 * |            -------------------------------------------------------------- |
33
 * | Lock Mode: |                                                          |v| |
34
 * |            -------------------------------------------------------------- |
35
 * |                                                                           |
36
 * | - Query Hints ----------------------------------------------------------- |
37
 * | | --------------------------------------------------------------------- | |
38
 * | | |                                                                   | | |
39
 * | | | QueryHintsComposite                                               | | |
40
 * | | |                                                                   | | |
41
 * | | --------------------------------------------------------------------- | |
42
 * | ------------------------------------------------------------------------- |
43
 * -----------------------------------------------------------------------------</pre>
44
 *
45
 *
46
 * @see NamedQuery2_0
47
 * @see NamedQueriesComposite - The parent container
48
 * @see QueryHintsComposite
49
 *
50
 * @version 2.0
51
 * @since 2.0
22
 */
52
 */
23
public class NamedQueryProperty2_0Composite extends NamedQueryPropertyComposite<NamedQuery2_0>
53
public class NamedQueryProperty2_0Composite extends Pane<NamedQuery2_0> {
24
{
54
25
	/**
55
	/**
26
	 * Creates a new <code>NamedQueryProperty2_0Composite</code>.
56
	 * Creates a new <code>NamedQueryProperty2_0Composite</code>.
27
	 *
57
	 *
Lines 30-60 Link Here
30
	 * @param parent The parent container
60
	 * @param parent The parent container
31
	 */
61
	 */
32
	public NamedQueryProperty2_0Composite(Pane<?> parentPane,
62
	public NamedQueryProperty2_0Composite(Pane<?> parentPane,
33
	                                   PropertyValueModel<NamedQuery2_0> subjectHolder,
63
	                                      PropertyValueModel<NamedQuery2_0> subjectHolder,
34
	                                   Composite parent) {
64
	                                      Composite parent) {
35
65
36
		super(parentPane, subjectHolder, parent);
66
		super(parentPane, subjectHolder, parent);
37
	}
67
	}
38
68
69
	protected WritablePropertyValueModel<String> buildNameTextHolder() {
70
		return new PropertyAspectAdapter<NamedQuery2_0, String>(getSubjectHolder(), Query.NAME_PROPERTY) {
71
			@Override
72
			protected String buildValue_() {
73
				return this.subject.getName();
74
			}
75
76
			@Override
77
			protected void setValue_(String value) {
78
				if (value.length() == 0) {
79
					value = null;
80
				}
81
				this.subject.setName(value);
82
			}
83
		};
84
	}
85
86
	protected WritablePropertyValueModel<String> buildQueryHolder() {
87
		return new PropertyAspectAdapter<NamedQuery2_0, String>(getSubjectHolder(), Query.QUERY_PROPERTY) {
88
			@Override
89
			protected String buildValue_() {
90
				return this.subject.getQuery();
91
			}
92
93
			@Override
94
			protected void setValue_(String value) {
95
				this.subject.setQuery(value);
96
			}
97
		};
98
	}
99
100
	/**
101
	 * {@inheritDoc}
102
	 */
39
	@Override
103
	@Override
40
	protected void initializeLayout(Composite container) {
104
	protected void initializeLayout(Composite container) {
41
		
105
106
		// Name widgets
42
		this.addLabeledText(
107
		this.addLabeledText(
43
			container, 
108
			container,
44
			JptUiDetailsMessages.NamedQueryComposite_nameTextLabel, 
109
			JptUiDetailsMessages.NamedQueryComposite_nameTextLabel,
45
			this.buildNameTextHolder());
110
			this.buildNameTextHolder());
46
111
112
		JpaJpqlContentProposalProvider provider = new JpaJpqlContentProposalProvider(
113
			container,
114
			getSubjectHolder(),
115
			buildQueryHolder()
116
		);
117
47
		// Query text area
118
		// Query text area
48
		this.addLabeledMultiLineText(
119
		Composite queryWidgets = this.addLabeledComposite(
49
			container,
120
			container,
50
			JptUiDetailsMessages.NamedQueryPropertyComposite_query,
121
			JptUiDetailsMessages.NamedQueryPropertyComposite_query,
51
			this.buildQueryHolder(),
122
			provider.getStyledText()
123
		);
124
125
		// Install the content assist icon at the top left of the StyledText.
126
		// Note: For some reason, this needs to be done after the StyledText
127
		//       is added to the labeled composite
128
		provider.installControlDecoration();
129
130
		adjustMultiLineTextLayout(
131
			queryWidgets,
52
			4,
132
			4,
53
			null
133
			provider.getStyledText(),
134
			provider.getStyledText().getLineHeight()
54
		);
135
		);
55
136
137
		// Lock Mode type
56
		new LockModeComposite(this, container);
138
		new LockModeComposite(this, container);
57
			
139
58
		// Query Hints pane
140
		// Query Hints pane
59
		container = this.addTitledGroup(
141
		container = this.addTitledGroup(
60
			this.addSubPane(container, 5),
142
			this.addSubPane(container, 5),
Lines 63-67 Link Here
63
145
64
		new QueryHintsComposite(this, container);
146
		new QueryHintsComposite(this, container);
65
	}
147
	}
66
	
148
}
67
}
(-)src/org/eclipse/jpt/jpa/ui/internal/jpa2/details/Queries2_0Composite.java (-4 / +2 lines)
Lines 15-21 Link Here
15
import org.eclipse.jpt.jpa.core.context.Query;
15
import org.eclipse.jpt.jpa.core.context.Query;
16
import org.eclipse.jpt.jpa.core.context.QueryContainer;
16
import org.eclipse.jpt.jpa.core.context.QueryContainer;
17
import org.eclipse.jpt.jpa.core.jpa2.context.NamedQuery2_0;
17
import org.eclipse.jpt.jpa.core.jpa2.context.NamedQuery2_0;
18
import org.eclipse.jpt.jpa.ui.internal.details.NamedQueryPropertyComposite;
19
import org.eclipse.jpt.jpa.ui.internal.details.QueriesComposite;
18
import org.eclipse.jpt.jpa.ui.internal.details.QueriesComposite;
20
import org.eclipse.swt.widgets.Composite;
19
import org.eclipse.swt.widgets.Composite;
21
import org.eclipse.ui.part.PageBook;
20
import org.eclipse.ui.part.PageBook;
Lines 34-42 Link Here
34
		super(parentPane, subjectHolder, parent);
33
		super(parentPane, subjectHolder, parent);
35
	}
34
	}
36
	
35
	
37
	
38
	@Override
36
	@Override
39
	protected NamedQueryPropertyComposite<NamedQuery2_0> buildNamedQueryPropertyComposite(PageBook pageBook) {
37
	protected Pane<NamedQuery2_0> buildNamedQueryPropertyComposite(PageBook pageBook) {
40
		return new NamedQueryProperty2_0Composite(
38
		return new NamedQueryProperty2_0Composite(
41
			this,
39
			this,
42
			this.buildNamedQuery2_0Holder(),
40
			this.buildNamedQuery2_0Holder(),
Lines 51-54 Link Here
51
			}
49
			}
52
		};
50
		};
53
	}
51
	}
54
}
52
}
(-)src/org/eclipse/jpt/jpa/ui/internal/jpql/JpaJpqlContentProposalProvider.java (+698 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
5
 * which accompanies this distribution.
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.ui.internal.jpql;
15
16
import java.text.MessageFormat;
17
import java.util.Collections;
18
import java.util.Comparator;
19
import java.util.List;
20
import java.util.Locale;
21
import java.util.ResourceBundle;
22
import org.eclipse.core.commands.AbstractHandler;
23
import org.eclipse.core.commands.ExecutionEvent;
24
import org.eclipse.core.commands.ExecutionException;
25
import org.eclipse.core.commands.IHandler;
26
import org.eclipse.core.commands.ParameterizedCommand;
27
import org.eclipse.core.expressions.EvaluationResult;
28
import org.eclipse.core.expressions.Expression;
29
import org.eclipse.core.expressions.ExpressionInfo;
30
import org.eclipse.core.expressions.IEvaluationContext;
31
import org.eclipse.jface.bindings.Binding;
32
import org.eclipse.jface.bindings.Trigger;
33
import org.eclipse.jface.bindings.keys.KeyStroke;
34
import org.eclipse.jface.bindings.keys.SWTKeySupport;
35
import org.eclipse.jface.fieldassist.ControlDecoration;
36
import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
37
import org.eclipse.jface.internal.text.html.HTMLTextPresenter;
38
import org.eclipse.jface.text.BadLocationException;
39
import org.eclipse.jface.text.DefaultInformationControl;
40
import org.eclipse.jface.text.DefaultTextHover;
41
import org.eclipse.jface.text.Document;
42
import org.eclipse.jface.text.DocumentEvent;
43
import org.eclipse.jface.text.IDocument;
44
import org.eclipse.jface.text.IDocumentListener;
45
import org.eclipse.jface.text.IInformationControl;
46
import org.eclipse.jface.text.IInformationControlCreator;
47
import org.eclipse.jface.text.ITextHover;
48
import org.eclipse.jface.text.ITextViewer;
49
import org.eclipse.jface.text.Position;
50
import org.eclipse.jface.text.contentassist.ContentAssistant;
51
import org.eclipse.jface.text.contentassist.ICompletionProposal;
52
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
53
import org.eclipse.jface.text.contentassist.IContentAssistant;
54
import org.eclipse.jface.text.contentassist.IContextInformation;
55
import org.eclipse.jface.text.contentassist.IContextInformationValidator;
56
import org.eclipse.jface.text.source.Annotation;
57
import org.eclipse.jface.text.source.AnnotationModel;
58
import org.eclipse.jface.text.source.DefaultAnnotationHover;
59
import org.eclipse.jface.text.source.IAnnotationHover;
60
import org.eclipse.jface.text.source.ISourceViewer;
61
import org.eclipse.jface.text.source.SourceViewer;
62
import org.eclipse.jface.text.source.SourceViewerConfiguration;
63
import org.eclipse.jpt.common.ui.internal.listeners.SWTPropertyChangeListenerWrapper;
64
import org.eclipse.jpt.common.utility.internal.StringTools;
65
import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
66
import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener;
67
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
68
import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel;
69
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
70
import org.eclipse.jpt.jpa.core.context.NamedQuery;
71
import org.eclipse.jpt.jpa.ui.internal.JptUiMessages;
72
import org.eclipse.osgi.util.NLS;
73
import org.eclipse.persistence.jpa.jpql.JPQLQueryProblem;
74
import org.eclipse.swt.SWT;
75
import org.eclipse.swt.custom.StyledText;
76
import org.eclipse.swt.events.DisposeEvent;
77
import org.eclipse.swt.events.DisposeListener;
78
import org.eclipse.swt.events.FocusEvent;
79
import org.eclipse.swt.events.FocusListener;
80
import org.eclipse.swt.events.ModifyEvent;
81
import org.eclipse.swt.events.ModifyListener;
82
import org.eclipse.swt.graphics.Image;
83
import org.eclipse.swt.widgets.Composite;
84
import org.eclipse.swt.widgets.Shell;
85
import org.eclipse.ui.ISources;
86
import org.eclipse.ui.IWorkbench;
87
import org.eclipse.ui.PlatformUI;
88
import org.eclipse.ui.actions.ActionFactory;
89
import org.eclipse.ui.editors.text.EditorsUI;
90
import org.eclipse.ui.handlers.IHandlerActivation;
91
import org.eclipse.ui.handlers.IHandlerService;
92
import org.eclipse.ui.internal.editors.text.EditorsPlugin;
93
import org.eclipse.ui.keys.IBindingService;
94
import org.eclipse.ui.swt.IFocusService;
95
import org.eclipse.ui.texteditor.AnnotationPreference;
96
import org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess;
97
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
98
import org.eclipse.ui.texteditor.SourceViewerDecorationSupport;
99
100
/**
101
 * This provider installs content assist support on a {@link StyledText} widget in order to give
102
 * choices at any given position within a JPQL query.
103
 * <p>
104
 * TODO. Add syntax highlight for the JPQL identifiers.
105
 *
106
 * @version 3.0
107
 * @since 3.0
108
 * @author Pascal Filion
109
 */
110
@SuppressWarnings({"nls", "restriction"})
111
public final class JpaJpqlContentProposalProvider extends JpqlCompletionProposalComputer<ICompletionProposal> {
112
113
	/**
114
	 * This model holds onto the {@link Annotation annotations} that have been created for each
115
	 * {@link JPQLQueryProblem}
116
	 */
117
	private AnnotationModel annotationModel;
118
119
	/**
120
	 * The decoration support required to paint the {@link Annotation annotations}, which are the
121
	 * JPQL problems.
122
	 */
123
	private SourceViewerDecorationSupport decorationSupport;
124
125
	/**
126
	 * This handler will trigger an event that will be used to notify the {@link SourceViewer} to
127
	 * invoke the content assist.
128
	 */
129
	private IHandlerActivation handlerActivation;
130
131
	/**
132
	 * The position within the JPQL query.
133
	 */
134
	private int position;
135
136
	/**
137
	 * The holder of the named query.
138
	 */
139
	private PropertyValueModel<? extends NamedQuery> queryHolder;
140
141
	/**
142
	 * The {@link ResourceBundle} that contains the JPQL problems.
143
	 */
144
	private ResourceBundle resourceBundle;
145
146
	/**
147
	 * This viewer is used to install various functionality over the {@link StyledText}.
148
	 */
149
	private SourceViewer sourceViewer;
150
151
	/**
152
	 * The configuration object used to configure the {@link SourceViewer}.
153
	 */
154
	private JpqlSourceViewerConfiguration sourceViewerConfiguration;
155
156
	/**
157
	 * The widget used to display the JPQL query.
158
	 */
159
	private StyledText styledText;
160
161
	/**
162
	 * This listener is used to dispose the {@link org.eclipse.persistence.jpa.jpql.JPQLQueryHelper
163
	 * JPQLQueryHelper} when the subject changes and to reset the undo manager in order to prevent
164
	 * the query from being entirely deleted with an undo.
165
	 */
166
	private PropertyChangeListener subjectChangeListener;
167
168
	/**
169
	 * The holder of the JPQL query.
170
	 */
171
	private WritablePropertyValueModel<String> textHolder;
172
173
	/**
174
	 * Listens to the JPQL query and keep the {@link Document} in sync.
175
	 */
176
	private PropertyChangeListener textListener;
177
178
	/**
179
	 * The unique identifier - appended by hashCode() - used to register the widget with the focus
180
	 * handler.
181
	 */
182
	private static final String CONTROL_ID = "jpql.focus.control";
183
184
	/**
185
	 * The unique identifier used to mark an {@link Annotation} as a JPQL problem.
186
	 */
187
	private static final String ERROR_TYPE = "org.eclipse.jdt.ui.error";
188
189
	/**
190
	 * Creates a new <code>JpaJpqlContentProposalProvider</code>.
191
	 *
192
	 * @param parent The parent {@link Composite} where to add the JPQL query editor
193
	 * @param queryHolder The holder of the named query
194
	 * @param textHolder The holder of the JPQL query
195
	 */
196
	public JpaJpqlContentProposalProvider(Composite parent,
197
	                                      PropertyValueModel<? extends NamedQuery> queryHolder,
198
	                                      WritablePropertyValueModel<String> textHolder) {
199
200
		super();
201
		initialize(parent, queryHolder, textHolder);
202
	}
203
204
	private void activateHandler() {
205
206
		IWorkbench workbench = PlatformUI.getWorkbench();
207
		IFocusService focusService = (IFocusService) workbench.getService(IFocusService.class);
208
		IHandlerService handlerService = (IHandlerService) workbench.getService(IHandlerService.class);
209
210
		if ((focusService != null) && (handlerService != null)) {
211
212
			focusService.addFocusTracker(styledText, CONTROL_ID + hashCode());
213
214
			Expression expression = buildExpression();
215
			IHandler handler = buildHandler();
216
217
			handlerActivation = handlerService.activateHandler(
218
				ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS,
219
				handler,
220
				expression
221
			);
222
223
			handlerActivation = handlerService.activateHandler(
224
				ActionFactory.UNDO.getCommandId(),
225
				handler,
226
				expression
227
			);
228
229
			handlerActivation = handlerService.activateHandler(
230
				ActionFactory.REDO.getCommandId(),
231
				handler,
232
				expression
233
			);
234
		}
235
	}
236
237
	@SuppressWarnings("unchecked")
238
	private List<AnnotationPreference> annotationPreferences() {
239
		return EditorsPlugin.getDefault().getMarkerAnnotationPreferences().getAnnotationPreferences();
240
	}
241
242
	private DisposeListener buildDisposeListener() {
243
		return new DisposeListener() {
244
			public void widgetDisposed(DisposeEvent e) {
245
				dispose();
246
			}
247
		};
248
	}
249
250
	private IDocumentListener buildDocumentListener() {
251
		return new IDocumentListener() {
252
			public void documentAboutToBeChanged(DocumentEvent event) {
253
			}
254
			public void documentChanged(DocumentEvent event) {
255
				try {
256
					IDocument document = event.getDocument();
257
					String text = document.get(0, document.getLength());
258
					textHolder.setValue(text);
259
				}
260
				catch (BadLocationException e) {
261
					// Simply ignore, should never happen
262
				}
263
			}
264
		};
265
	}
266
267
	private Expression buildExpression() {
268
		return new Expression() {
269
			@Override
270
			public void collectExpressionInfo(ExpressionInfo info) {
271
				info.addVariableNameAccess(ISources.ACTIVE_FOCUS_CONTROL_NAME);
272
			}
273
			@Override
274
			public EvaluationResult evaluate(IEvaluationContext context) {
275
				Object variable = context.getVariable(ISources.ACTIVE_FOCUS_CONTROL_NAME);
276
				return (variable == styledText) ? EvaluationResult.TRUE : EvaluationResult.FALSE;
277
			}
278
		};
279
	}
280
281
	private FocusListener buildFocusListener() {
282
		return new FocusListener() {
283
			public void focusGained(FocusEvent e) {
284
			}
285
			public void focusLost(FocusEvent e) {
286
				// Only dispose the query helper if the content proposal popup doesn't grab the focus
287
				if (!sourceViewerConfiguration.contentAssistant.hasProposalPopupFocus()) {
288
					disposeQueryHelper();
289
				}
290
			}
291
		};
292
	}
293
294
	private IHandler buildHandler() {
295
		return new AbstractHandler() {
296
			public Object execute(ExecutionEvent event) throws ExecutionException {
297
				String commandId = event.getCommand().getId();
298
299
				// Content Assist
300
				if (ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS.equals(commandId)) {
301
					sourceViewer.doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS);
302
				}
303
				// Undo
304
				else if (ActionFactory.UNDO.getCommandId().equals(commandId)) {
305
					if (sourceViewer.getUndoManager().undoable()) {
306
						sourceViewer.getUndoManager().undo();
307
					}
308
				}
309
				// Redo
310
				else if (ActionFactory.REDO.getCommandId().equals(commandId)) {
311
					if (sourceViewer.getUndoManager().redoable()) {
312
						sourceViewer.getUndoManager().redo();
313
					}
314
				}
315
316
				return null;
317
			}
318
		};
319
	}
320
321
	private String buildMessage(JPQLQueryProblem problem) {
322
		String message = resourceBundle().getString(problem.getMessageKey());
323
		message = MessageFormat.format(message, (Object[]) problem.getMessageArguments());
324
		return message;
325
	}
326
327
	private ModifyListener buildModifyListener() {
328
		return new ModifyListener() {
329
			public void modifyText(ModifyEvent e) {
330
				validate();
331
			}
332
		};
333
	}
334
335
	private Comparator<JPQLQueryProblem> buildProblemComparator() {
336
		return new Comparator<JPQLQueryProblem>() {
337
			public int compare(JPQLQueryProblem problem1, JPQLQueryProblem problem2) {
338
				int result = problem1.getStartPosition() - problem2.getStartPosition();
339
				if (result == 0) {
340
					result = problem1.getEndPosition() - problem2.getEndPosition();
341
				}
342
				return result;
343
			}
344
		};
345
	}
346
347
	/**
348
	 * {@inheritDoc}
349
	 */
350
	@Override
351
	ICompletionProposal buildProposal(String proposal,
352
	                                  String displayString,
353
	                                  String additionalInfo,
354
	                                  Image image,
355
	                                  int cursorOffset) {
356
357
		return new JpqlCompletionProposal(
358
			contentAssistProposals,
359
			proposal,
360
			displayString,
361
			additionalInfo,
362
			image,
363
			namedQuery,
364
			actualQuery,
365
			jpqlQuery,
366
			offset,
367
			position,
368
			cursorOffset,
369
			false
370
		);
371
	}
372
373
	private PropertyChangeListener buildSubjectChangeListener() {
374
		return new PropertyChangeListener() {
375
			public void propertyChanged(PropertyChangeEvent e) {
376
				subjectChanged(e);
377
			}
378
		};
379
	}
380
381
	private PropertyChangeListener buildTextListener() {
382
		return new SWTPropertyChangeListenerWrapper(new PropertyChangeListener() {
383
			public void propertyChanged(PropertyChangeEvent event) {
384
				String text = (String) event.getNewValue();
385
				if (text == null) {
386
					text = StringTools.EMPTY_STRING;
387
				}
388
				if (!styledText.getText().equals(text)) {
389
					sourceViewer.getDocument().set(text);
390
				}
391
			}
392
		});
393
	}
394
395
	private Image contentAssistImage() {
396
		FieldDecorationRegistry registry = FieldDecorationRegistry.getDefault();
397
		return registry.getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL).getImage();
398
	}
399
400
	/**
401
	 * Makes sure the {@link Color} used to paint the underlying problem is disposed when the
402
	 * {@link StyledText} widget is disposed.
403
	 */
404
	private void dispose() {
405
406
		sessionEnded();
407
408
		decorationSupport.dispose();
409
		textHolder.removePropertyChangeListener(PropertyValueModel.VALUE, textListener);
410
		queryHolder.removePropertyChangeListener(PropertyValueModel.VALUE, subjectChangeListener);
411
412
		IWorkbench workbench = PlatformUI.getWorkbench();
413
		IHandlerService handlerService = (IHandlerService) workbench.getService(IHandlerService.class);
414
		handlerService.deactivateHandler(handlerActivation);
415
	}
416
417
	private void disposeQueryHelper() {
418
		queryHelper.dispose();
419
		queryHelper.disposeProvider();
420
	}
421
422
	private KeyStroke findContentAssistTrigger() {
423
424
		IBindingService bindingService = (IBindingService) PlatformUI.getWorkbench().getService(IBindingService.class);
425
426
		// Dig through the list of available bindings to find the one for content assist
427
		for (Binding binding : bindingService.getBindings()) {
428
			if (isContentAssistBinding(binding)) {
429
				Trigger[] triggers = binding.getTriggerSequence().getTriggers();
430
				if ((triggers != null) && (triggers.length > 0)) {
431
					return (KeyStroke) triggers[0];
432
				}
433
			}
434
		}
435
436
		// The default trigger was not found, use the default
437
		return KeyStroke.getInstance(SWT.CTRL, ' ');
438
	}
439
440
	/**
441
	 * Returns the widget used to display the JPQL query.
442
	 *
443
	 * @return The main widget
444
	 */
445
	public StyledText getStyledText() {
446
		return styledText;
447
	}
448
449
	private void initialize(Composite parent,
450
	                        PropertyValueModel<? extends NamedQuery> queryHolder,
451
	                        WritablePropertyValueModel<String> textHolder) {
452
453
		this.queryHolder     = queryHolder;
454
		this.annotationModel = new AnnotationModel();
455
		this.textHolder      = textHolder;
456
457
		// Make sure the StyledText is kept in sync with the text holder
458
		textListener = buildTextListener();
459
		textHolder.addPropertyChangeListener(PropertyValueModel.VALUE, textListener);
460
461
		// Make sure the user can't delete the entire query when doing undo
462
		subjectChangeListener = buildSubjectChangeListener();
463
		queryHolder.addPropertyChangeListener(PropertyValueModel.VALUE, subjectChangeListener);
464
465
		// Create the SourceViewer, which is responsible for everything: content assist, tool tip
466
		// hovering over the annotation (problems), etc
467
		sourceViewer = new SourceViewer(parent, null, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL | SWT.H_SCROLL | SWT.FLAT);
468
		sourceViewerConfiguration = new JpqlSourceViewerConfiguration();
469
		sourceViewer.configure(sourceViewerConfiguration);
470
		sourceViewer.setDocument(new Document(), annotationModel);
471
		sourceViewer.getDocument().addDocumentListener(buildDocumentListener());
472
473
		styledText = sourceViewer.getTextWidget();
474
		styledText.addFocusListener(buildFocusListener());
475
		styledText.addModifyListener(buildModifyListener());
476
		styledText.addDisposeListener(buildDisposeListener());
477
478
		// Add the support for painting the annotations (JPQL problems) in the source viewer
479
		installDecorationSupport();
480
481
		// Bind the content assist key trigger with the handler service
482
		activateHandler();
483
484
		// Install a custom context menu to the widget
485
		TextTransferHandler.installContextMenu(styledText, sourceViewer.getUndoManager());
486
	}
487
488
	/**
489
	 * Installs the content assist icon at the top left of the {@link StyledText}.
490
	 */
491
	public void installControlDecoration() {
492
493
		// Retrieve the content assist trigger
494
		KeyStroke contentAssistTrigger = findContentAssistTrigger();
495
		String key = SWTKeySupport.getKeyFormatterForPlatform().format(contentAssistTrigger);
496
497
		// Add the context assist icon at the top left corner of the StyledText
498
		ControlDecoration decoration = new ControlDecoration(styledText, SWT.LEFT | SWT.TOP);
499
		decoration.setDescriptionText(NLS.bind(JptUiMessages.JpqlContentProposalProvider_Description, key));
500
		decoration.setImage(contentAssistImage());
501
		decoration.setShowOnlyOnFocus(true);
502
	}
503
504
	private void installDecorationSupport() {
505
506
		decorationSupport = new SourceViewerDecorationSupport(
507
			sourceViewer,
508
			null,
509
			new DefaultMarkerAnnotationAccess(),
510
			EditorsPlugin.getDefault().getSharedTextColors()
511
		);
512
513
		for (AnnotationPreference preference : annotationPreferences()) {
514
			decorationSupport.setAnnotationPreference(preference);
515
		}
516
517
		decorationSupport.install(EditorsPlugin.getDefault().getPreferenceStore());
518
	}
519
520
	private boolean isContentAssistBinding(Binding binding) {
521
522
		ParameterizedCommand command = binding.getParameterizedCommand();
523
524
		return command != null &&
525
		       command.getCommand() != null &&
526
		       command.getCommand().getId().equals(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
527
	}
528
529
	private NamedQuery query() {
530
		return queryHolder.getValue();
531
	}
532
533
	private ResourceBundle resourceBundle() {
534
		if (resourceBundle == null) {
535
			resourceBundle = ResourceBundle.getBundle(
536
				"jpa_jpql_validation",
537
				Locale.getDefault(),
538
				JptJpaCorePlugin.class.getClassLoader()
539
			);
540
		}
541
		return resourceBundle;
542
	}
543
544
	private List<JPQLQueryProblem> sortProblems(List<JPQLQueryProblem> problems) {
545
		Collections.sort(problems, buildProblemComparator());
546
		return problems;
547
	}
548
549
	private void subjectChanged(PropertyChangeEvent e) {
550
551
		// Disposes of the internal data since the subject changed
552
		disposeQueryHelper();
553
554
		// Prevent undoing the actual query that was set
555
		if (e.getNewValue() != null) {
556
			sourceViewer.getUndoManager().reset();
557
		}
558
	}
559
560
	/**
561
	 * Validates the given JPQL query and add highlights where problems have been found.
562
	 */
563
	private void validate() {
564
565
		NamedQuery query = query();
566
		annotationModel.removeAllAnnotations();
567
568
		if ((query != null) && !styledText.isDisposed()) {
569
			try {
570
				String jpqlQuery = styledText.getText();
571
				queryHelper.setQuery(query, jpqlQuery);
572
				String parsedJpqlQuery = queryHelper.getParsedJPQLQuery();
573
574
				for (JPQLQueryProblem problem : sortProblems(queryHelper.validate())) {
575
576
					// Create the range
577
					int[] positions = queryHelper.buildPositions(problem, parsedJpqlQuery, jpqlQuery);
578
579
					// Add the problem to the tool tip
580
					Annotation annotation = new Annotation(ERROR_TYPE, true, buildMessage(problem));
581
					annotationModel.addAnnotation(annotation, new Position(positions[0], positions[1] - positions[0]));
582
				}
583
			}
584
			finally {
585
				queryHelper.dispose();
586
			}
587
		}
588
	}
589
590
	/**
591
	 * This processor is responsible to create the list of {@link ICompletionProposal proposals}
592
	 * based on the position of the cursor within the query.
593
	 */
594
	private class ContentAssistProcessor implements IContentAssistProcessor {
595
596
		/**
597
		 * {@inheritDoc}
598
		 */
599
		public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
600
601
			JpaJpqlContentProposalProvider.this.position = offset;
602
603
			String jpqlQuery = viewer.getDocument().get();
604
			List<ICompletionProposal> proposals = buildProposals(query(), jpqlQuery, 0, position);
605
			return proposals.toArray(new ICompletionProposal[proposals.size()]);
606
		}
607
608
		/**
609
		 * {@inheritDoc}
610
		 */
611
		public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
612
			return null;
613
		}
614
615
		/**
616
		 * {@inheritDoc}
617
		 */
618
		public char[] getCompletionProposalAutoActivationCharacters() {
619
			return null;
620
		}
621
622
		/**
623
		 * {@inheritDoc}
624
		 */
625
		public char[] getContextInformationAutoActivationCharacters() {
626
			return null;
627
		}
628
629
		/**
630
		 * {@inheritDoc}
631
		 */
632
		public IContextInformationValidator getContextInformationValidator() {
633
			return null;
634
		}
635
636
		/**
637
		 * {@inheritDoc}
638
		 */
639
		public String getErrorMessage() {
640
			return null;
641
		}
642
	}
643
644
	private class JpqlSourceViewerConfiguration extends SourceViewerConfiguration {
645
646
		/**
647
		 * Keeps track of the content assist since we need to know when the popup is opened or not.
648
		 */
649
		ContentAssistant contentAssistant;
650
651
		private IInformationControlCreator buildInformationControlCreator() {
652
			return new IInformationControlCreator() {
653
				public IInformationControl createInformationControl(Shell parent) {
654
					return new DefaultInformationControl(
655
						parent,
656
						EditorsUI.getTooltipAffordanceString(),
657
						new HTMLTextPresenter(true)
658
					);
659
				}
660
			};
661
		}
662
663
		/**
664
		 * {@inheritDoc}
665
		 */
666
		@Override
667
		public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
668
			return new DefaultAnnotationHover();
669
		}
670
671
		/**
672
		 * {@inheritDoc}
673
		 */
674
		@Override
675
		public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
676
			contentAssistant = new ContentAssistant();
677
			contentAssistant.setContentAssistProcessor(new ContentAssistProcessor(), IDocument.DEFAULT_CONTENT_TYPE);
678
			contentAssistant.setInformationControlCreator(buildInformationControlCreator());
679
			return contentAssistant;
680
		}
681
682
		/**
683
		 * {@inheritDoc}
684
		 */
685
		@Override
686
		public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
687
			return new DefaultTextHover(sourceViewer);
688
		}
689
690
		/**
691
		 * {@inheritDoc}
692
		 */
693
		@Override
694
		public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType, int stateMask) {
695
			return new DefaultTextHover(sourceViewer);
696
		}
697
	}
698
}
(-)src/org/eclipse/jpt/jpa/ui/internal/jpql/JpaJpqlJavaCompletionProposalComputer.java (+320 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
5
 * which accompanies this distribution.
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.ui.internal.jpql;
15
16
import java.util.Collections;
17
import java.util.Iterator;
18
import java.util.List;
19
import org.eclipse.core.resources.IFile;
20
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.core.runtime.IStatus;
22
import org.eclipse.core.runtime.Status;
23
import org.eclipse.jdt.core.CompletionContext;
24
import org.eclipse.jdt.core.ICompilationUnit;
25
import org.eclipse.jdt.core.JavaModelException;
26
import org.eclipse.jdt.core.dom.ASTNode;
27
import org.eclipse.jdt.core.dom.AbstractTypeDeclaration;
28
import org.eclipse.jdt.core.dom.Annotation;
29
import org.eclipse.jdt.core.dom.ArrayInitializer;
30
import org.eclipse.jdt.core.dom.CompilationUnit;
31
import org.eclipse.jdt.core.dom.IExtendedModifier;
32
import org.eclipse.jdt.core.dom.MemberValuePair;
33
import org.eclipse.jdt.core.dom.NormalAnnotation;
34
import org.eclipse.jdt.core.dom.SingleMemberAnnotation;
35
import org.eclipse.jdt.core.dom.StringLiteral;
36
import org.eclipse.jdt.ui.text.java.ContentAssistInvocationContext;
37
import org.eclipse.jdt.ui.text.java.IJavaCompletionProposalComputer;
38
import org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext;
39
import org.eclipse.jface.text.contentassist.ICompletionProposal;
40
import org.eclipse.jface.text.contentassist.IContextInformation;
41
import org.eclipse.jpt.common.core.internal.utility.jdt.ASTTools;
42
import org.eclipse.jpt.common.core.utility.TextRange;
43
import org.eclipse.jpt.common.utility.internal.StringTools;
44
import org.eclipse.jpt.jpa.core.JpaFile;
45
import org.eclipse.jpt.jpa.core.JpaStructureNode;
46
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
47
import org.eclipse.jpt.jpa.core.context.NamedQuery;
48
import org.eclipse.jpt.jpa.core.context.java.JavaEntity;
49
import org.eclipse.jpt.jpa.core.context.java.JavaNamedQuery;
50
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
51
import org.eclipse.jpt.jpa.core.context.java.JavaTypeMapping;
52
import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
53
import org.eclipse.jpt.jpa.ui.internal.JptUiMessages;
54
import org.eclipse.persistence.jpa.jpql.ExpressionTools;
55
import org.eclipse.swt.graphics.Image;
56
57
/**
58
 * This computer adds content assist support when it is invoked inside the query element of {@link
59
 * javax.persistence.NamedQuery &#64;NamedQuery}.
60
 *
61
 * @version 3.0
62
 * @since 3.0
63
 * @author Pascal Filion
64
 */
65
@SuppressWarnings("restriction")
66
public final class JpaJpqlJavaCompletionProposalComputer extends JpqlCompletionProposalComputer<ICompletionProposal>
67
                                                         implements IJavaCompletionProposalComputer {
68
69
	/**
70
	 * Creates a new <code>JpaJpqlJavaCompletionProposalComputer</code>.
71
	 */
72
	public JpaJpqlJavaCompletionProposalComputer() {
73
		super();
74
	}
75
76
	/**
77
	 * {@inheritDoc}
78
	 */
79
	@Override
80
	ICompletionProposal buildProposal(String proposal,
81
	                                  String displayString,
82
	                                  String additionalInfo,
83
	                                  Image image,
84
	                                  int cursorOffset) {
85
86
		return new JpqlCompletionProposal(
87
			contentAssistProposals,
88
			proposal,
89
			displayString,
90
			additionalInfo,
91
			image,
92
			namedQuery,
93
			actualQuery,
94
			jpqlQuery,
95
			offset + 1, // +1 is to skip the opening "
96
			position,
97
			cursorOffset,
98
			true
99
		);
100
	}
101
102
	/**
103
	 * {@inheritDoc}
104
	 */
105
	public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context,
106
	                                                            IProgressMonitor monitor) {
107
108
		if (context instanceof JavaContentAssistInvocationContext) {
109
			monitor.beginTask(null, 100);
110
			try {
111
				return computeCompletionProposals((JavaContentAssistInvocationContext) context, monitor);
112
			}
113
			catch (Exception e) {
114
				Status status = new Status(IStatus.ERROR, JptJpaUiPlugin.PLUGIN_ID, JptUiMessages.JpaJpqlJavaCompletionProposalComputer_Error, e);
115
				JptJpaCorePlugin.log(status);
116
			}
117
			finally {
118
				monitor.done();
119
			}
120
		}
121
122
		return Collections.emptyList();
123
	}
124
125
	private List<ICompletionProposal> computeCompletionProposals(JavaContentAssistInvocationContext context,
126
	                                                             IProgressMonitor monitor) throws Exception {
127
128
		CompletionContext completionContext = context.getCoreContext();
129
130
		// The token "start" is the offset of the token's first character within the document.
131
		// A token start of -1 can means:
132
		// - It is inside the string representation of a unicode character, \\u0|0E9 where | is the
133
		//   cursor, then -1 is returned;
134
		// - The string is not valid (it has some invalid characters)
135
		int tokenStart = completionContext.getTokenStart();
136
		if (tokenStart == -1) return Collections.emptyList();
137
138
		int[] position = { completionContext.getOffset() - tokenStart - 1 };
139
		if (position[0] < 0) return Collections.emptyList();
140
141
		ICompilationUnit compilationUnit = context.getCompilationUnit();
142
		if (compilationUnit == null) return Collections.emptyList();
143
		CompilationUnit astRoot = ASTTools.buildASTRoot(compilationUnit);
144
145
		IFile file = getCorrespondingResource(compilationUnit);
146
		if (file == null) return Collections.emptyList();
147
148
		JpaFile jpaFile = JptJpaCorePlugin.getJpaFile(file);
149
		if (jpaFile == null) return Collections.emptyList();
150
151
		monitor.worked(80);
152
		checkCanceled(monitor);
153
154
		// Retrieve the JPA's model object
155
		NamedQuery namedQuery = namedQuery(astRoot, jpaFile, tokenStart);
156
		if (namedQuery == null) return Collections.emptyList();
157
158
		// Retrieve the actual value of the element "query" since the content assist can be
159
		// invoked before the model received the new content
160
		String jpqlQuery = jpqlQuery(astRoot, tokenStart, completionContext.getTokenEnd(), position);
161
162
		// Now create the proposals
163
		return buildProposals(namedQuery, jpqlQuery, tokenStart, position[0]);
164
	}
165
166
	/**
167
	 * {@inheritDoc}
168
	 */
169
	public List<IContextInformation> computeContextInformation(ContentAssistInvocationContext context,
170
	                                                           IProgressMonitor monitor) {
171
172
		return Collections.emptyList();
173
	}
174
175
	private NamedQuery findNamedQuery(JpaStructureNode structureNode,
176
	                                  CompilationUnit astRoot,
177
	                                  int tokenStart) {
178
179
		if (structureNode instanceof JavaPersistentType) {
180
			JavaPersistentType persistentType = (JavaPersistentType) structureNode;
181
			JavaTypeMapping typeMapping = persistentType.getMapping();
182
183
			if (typeMapping instanceof JavaEntity) {
184
				JavaEntity entity = (JavaEntity) typeMapping;
185
186
				for (Iterator<JavaNamedQuery> queries = entity.getQueryContainer().namedQueries(); queries.hasNext(); ) {
187
					JavaNamedQuery namedQuery = queries.next();
188
					TextRange textRange = namedQuery.getQueryAnnotation().getQueryTextRange(astRoot);
189
190
					if ((textRange != null) && textRange.includes(tokenStart)) {
191
						return namedQuery;
192
					}
193
				}
194
			}
195
		}
196
197
		return null;
198
	}
199
200
	private IFile getCorrespondingResource(ICompilationUnit compilationUnit) {
201
		try {
202
			return (IFile) compilationUnit.getCorrespondingResource();
203
		}
204
		catch (JavaModelException ex) {
205
			JptJpaCorePlugin.log(ex);
206
			return null;
207
		}
208
	}
209
210
	private boolean isInsideNode(ASTNode node, int tokenStart, int tokenEnd) {
211
		int startPosition = node.getStartPosition();
212
		return startPosition <= tokenStart &&
213
		       startPosition + node.getLength() >= tokenEnd;
214
	}
215
216
	private String jpqlQuery(CompilationUnit astRoot, int tokenStart, int tokenEnd, int[] position) {
217
218
		String jpqlQuery = retrieveQuery(astRoot, tokenStart, tokenEnd);
219
220
		if (jpqlQuery == null) {
221
			jpqlQuery = StringTools.EMPTY_STRING;
222
		}
223
		else if (StringTools.stringIsQuoted(jpqlQuery)) {
224
			jpqlQuery = jpqlQuery.substring(1, jpqlQuery.length() - 1);
225
		}
226
227
		return jpqlQuery;
228
	}
229
230
	/**
231
	 * {@inheritDoc}
232
	 */
233
	@Override
234
	String modifyJpqlQuery(String jpqlQuery, int[] position) {
235
		return ExpressionTools.unescape(jpqlQuery, position);
236
	}
237
238
	private NamedQuery namedQuery(CompilationUnit astRoot, JpaFile jpaFile, int tokenStart) {
239
240
		for (JpaStructureNode node : jpaFile.getRootStructureNodes()) {
241
			NamedQuery namedQuery = findNamedQuery(node, astRoot, tokenStart);
242
			if (namedQuery != null) {
243
				return namedQuery;
244
			}
245
		}
246
247
		return null;
248
	}
249
250
	/**
251
	 * This twisted code is meant to retrieve the real string value that is not escaped and to also
252
	 * retrieve the position within the non-escaped string. The query could have escape characters,
253
	 * such as \r, \n etc being written as \\r, \\n, the position is based on that escaped string,
254
	 * the conversion will convert them into \r and \r and adjust the position accordingly.
255
	 *
256
	 * @param astRoot The parsed tree representation of the Java source file
257
	 * @param tokenStart The beginning of the query expression of the {@link javax.persistence.NamedQuery
258
	 * &#64;NamedQuery}'s query member within the source file
259
	 * @param tokenEnd The end of the query member within the source file
260
	 * @param position The position of the cursor within the query expression
261
	 * @return The actual value retrieved from the query element
262
	 */
263
	@SuppressWarnings("unchecked")
264
	private String retrieveQuery(CompilationUnit astRoot, int tokenStart, int tokenEnd) {
265
266
		// Dig into the TypeDeclarations
267
		for (AbstractTypeDeclaration type : (List<AbstractTypeDeclaration>) astRoot.types()) {
268
269
			if (isInsideNode(type, tokenStart, tokenEnd)) {
270
271
				// Dig inside its modifiers and annotations
272
				for (IExtendedModifier modifier : (List<IExtendedModifier>) type.modifiers()) {
273
274
					if (!modifier.isAnnotation()) {
275
						continue;
276
					}
277
278
					Annotation annotation = (Annotation) modifier;
279
280
					// Dig inside the annotation
281
					if (isInsideNode(annotation, tokenStart, tokenEnd)) {
282
283
						// @NamedQueries({...})
284
						if (annotation.isSingleMemberAnnotation()) {
285
							SingleMemberAnnotation singleMemberAnnotation = (SingleMemberAnnotation) annotation;
286
							ArrayInitializer array = (ArrayInitializer) singleMemberAnnotation.getValue();
287
288
							for (org.eclipse.jdt.core.dom.Expression expression : (List<org.eclipse.jdt.core.dom.Expression>) array.expressions()) {
289
								if (isInsideNode(expression, tokenStart, tokenEnd)) {
290
									return retrieveQuery((NormalAnnotation) expression, tokenStart, tokenEnd);
291
								}
292
							}
293
						}
294
						// @NamedQuery()
295
						else if (annotation.isNormalAnnotation()) {
296
							return retrieveQuery((NormalAnnotation) annotation, tokenStart, tokenEnd);
297
						}
298
					}
299
				}
300
			}
301
		}
302
303
		return null;
304
	}
305
306
	@SuppressWarnings("unchecked")
307
	private String retrieveQuery(NormalAnnotation annotation, int tokenStart, int tokenEnd) {
308
309
		for (MemberValuePair pair : (List<MemberValuePair>) annotation.values()) {
310
			org.eclipse.jdt.core.dom.Expression expression = pair.getValue();
311
312
			if (isInsideNode(expression, tokenStart, tokenEnd)) {
313
				StringLiteral literal = (StringLiteral) pair.getValue();
314
				return literal.getEscapedValue();
315
			}
316
		}
317
318
		return null;
319
	}
320
}
(-)src/org/eclipse/jpt/jpa/ui/internal/jpql/JpaJpqlSseCompletionProposalComputer.java (+224 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
5
 * which accompanies this distribution.
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.ui.internal.jpql;
15
16
import java.util.Collections;
17
import java.util.Iterator;
18
import java.util.List;
19
import org.eclipse.core.filebuffers.FileBuffers;
20
import org.eclipse.core.filebuffers.ITextFileBuffer;
21
import org.eclipse.core.filebuffers.ITextFileBufferManager;
22
import org.eclipse.core.resources.IFile;
23
import org.eclipse.core.resources.IWorkspaceRoot;
24
import org.eclipse.core.resources.ResourcesPlugin;
25
import org.eclipse.core.runtime.IProgressMonitor;
26
import org.eclipse.core.runtime.IStatus;
27
import org.eclipse.core.runtime.Status;
28
import org.eclipse.jface.text.BadLocationException;
29
import org.eclipse.jface.text.IDocument;
30
import org.eclipse.jface.text.contentassist.ICompletionProposal;
31
import org.eclipse.jface.text.contentassist.IContextInformation;
32
import org.eclipse.jpt.common.core.utility.TextRange;
33
import org.eclipse.jpt.common.utility.internal.StringTools;
34
import org.eclipse.jpt.jpa.core.JpaFile;
35
import org.eclipse.jpt.jpa.core.JpaStructureNode;
36
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
37
import org.eclipse.jpt.jpa.core.context.PersistentType;
38
import org.eclipse.jpt.jpa.core.context.QueryContainer;
39
import org.eclipse.jpt.jpa.core.context.TypeMapping;
40
import org.eclipse.jpt.jpa.core.context.orm.EntityMappings;
41
import org.eclipse.jpt.jpa.core.context.orm.OrmEntity;
42
import org.eclipse.jpt.jpa.core.context.orm.OrmNamedQuery;
43
import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
44
import org.eclipse.jpt.jpa.ui.internal.JptUiMessages;
45
import org.eclipse.persistence.jpa.jpql.ExpressionTools;
46
import org.eclipse.swt.graphics.Image;
47
import org.eclipse.wst.sse.ui.contentassist.CompletionProposalInvocationContext;
48
import org.eclipse.wst.sse.ui.contentassist.ICompletionProposalComputer;
49
50
/**
51
 * This computer adds content assist support when it is invoked inside the &lt;query&gt; element
52
 * defined in a mapping file (ORM Configuration).
53
 *
54
 * @version 3.0
55
 * @since 3.0
56
 * @author Pascal Filion
57
 */
58
public final class JpaJpqlSseCompletionProposalComputer extends JpqlCompletionProposalComputer<ICompletionProposal>
59
                                                        implements ICompletionProposalComputer {
60
61
	/**
62
	 * Creates a new <code>JpaJpqlSseCompletionProposalComputer</code>.
63
	 */
64
	public JpaJpqlSseCompletionProposalComputer() {
65
		super();
66
	}
67
68
	/**
69
	 * {@inheritDoc}
70
	 */
71
	@Override
72
	ICompletionProposal buildProposal(String proposal,
73
	                                  String displayString,
74
	                                  String additionalInfo,
75
	                                  Image image,
76
	                                  int cursorOffset) {
77
78
		return new JpqlCompletionProposal(
79
			contentAssistProposals,
80
			proposal,
81
			displayString,
82
			additionalInfo,
83
			image,
84
			namedQuery,
85
			actualQuery,
86
			jpqlQuery,
87
			offset,
88
			position,
89
			cursorOffset,
90
			true
91
		);
92
	}
93
94
	/**
95
	 * {@inheritDoc}
96
	 */
97
	public List<ICompletionProposal> computeCompletionProposals(CompletionProposalInvocationContext context,
98
	                                                            IProgressMonitor monitor) {
99
100
		monitor.beginTask(null, 100);
101
102
		try {
103
			int offset = context.getInvocationOffset();
104
			if (offset == -1) return Collections.emptyList();
105
106
			ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
107
			ITextFileBuffer buffer = manager.getTextFileBuffer(context.getDocument());
108
			if (buffer == null) return Collections.emptyList();
109
110
			IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
111
			IFile file = root.getFile(buffer.getLocation());
112
113
			JpaFile jpaFile = JptJpaCorePlugin.getJpaFile(file);
114
			if (jpaFile == null) return Collections.emptyList();
115
116
			monitor.worked(80);
117
			checkCanceled(monitor);
118
119
			// Retrieve the JPA's model object
120
			int[] position = new int[1];
121
			OrmNamedQuery namedQuery = namedQuery(jpaFile, offset, position);
122
			if (namedQuery == null) return Collections.emptyList();
123
124
			// Keep track of the beginning of the text since the entire string is always replaced
125
			int tokenStart = offset - position[0];
126
127
			// Now create the proposals
128
			String jpqlQuery = jpqlQuery(namedQuery, context.getDocument());
129
			return buildProposals(namedQuery, jpqlQuery, tokenStart, position[0]);
130
		}
131
		catch (Exception e) {
132
			Status status = new Status(IStatus.ERROR, JptJpaUiPlugin.PLUGIN_ID, JptUiMessages.JpaJpqlSseCompletionProposalComputer_Error, e);
133
			JptJpaCorePlugin.log(status);
134
		}
135
		finally {
136
			monitor.done();
137
		}
138
139
		return Collections.emptyList();
140
	}
141
142
	/**
143
	 * {@inheritDoc}
144
	 */
145
	public List<IContextInformation> computeContextInformation(CompletionProposalInvocationContext context,
146
	                                                           IProgressMonitor monitor) {
147
148
		return Collections.emptyList();
149
	}
150
151
	private OrmNamedQuery findNamedQuery(JpaStructureNode structureNode, int offset, int[] position) {
152
153
		if (structureNode instanceof EntityMappings) {
154
			EntityMappings entityMappings = (EntityMappings) structureNode;
155
156
			// First look into the global queries
157
			OrmNamedQuery query = findNamedQuery(entityMappings.getQueryContainer(), offset, position);
158
159
			// Now traverse each entity
160
			if (query != null) {
161
				return query;
162
			}
163
164
			for (PersistentType persistentType : entityMappings.getPersistentTypes()) {
165
				TypeMapping typeMapping = persistentType.getMapping();
166
167
				if (typeMapping instanceof OrmEntity) {
168
					query = findNamedQuery(((OrmEntity) typeMapping).getQueryContainer(), offset, position);
169
170
					if (query != null) {
171
						return query;
172
					}
173
				}
174
			}
175
		}
176
177
		return null;
178
	}
179
180
	private OrmNamedQuery findNamedQuery(QueryContainer container, int offset, int[] position) {
181
182
		for (Iterator<OrmNamedQuery> queries = container.namedQueries(); queries.hasNext(); ) {
183
			OrmNamedQuery namedQuery = queries.next();
184
			TextRange textRange = namedQuery.getQueryTextRange();
185
186
			if (textRange.touches(offset)) {
187
				position[0] = offset - textRange.getOffset();
188
				return namedQuery;
189
			}
190
		}
191
192
		return null;
193
	}
194
195
	private String jpqlQuery(OrmNamedQuery namedQuery, IDocument document) {
196
		try {
197
			TextRange range = namedQuery.getQueryTextRange();
198
			return document.get(range.getOffset(), range.getLength());
199
		}
200
		catch (BadLocationException e) {
201
			return StringTools.EMPTY_STRING;
202
		}
203
	}
204
205
	/**
206
	 * {@inheritDoc}
207
	 */
208
	@Override
209
	String modifyJpqlQuery(String jpqlQuery, int[] position) {
210
		return ExpressionTools.unescape(jpqlQuery, position);
211
	}
212
213
	private OrmNamedQuery namedQuery(JpaFile jpaFile, int offset, int[] position) {
214
215
		for (JpaStructureNode node : jpaFile.getRootStructureNodes()) {
216
			OrmNamedQuery namedQuery = findNamedQuery(node, offset, position);
217
			if (namedQuery != null) {
218
				return namedQuery;
219
			}
220
		}
221
222
		return null;
223
	}
224
}
(-)src/org/eclipse/jpt/jpa/ui/internal/jpql/JpqlCompletionProposal.java (+158 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
5
 * which accompanies this distribution.
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.ui.internal.jpql;
15
16
import org.eclipse.jdt.core.IJavaProject;
17
import org.eclipse.jdt.ui.PreferenceConstants;
18
import org.eclipse.jface.text.BadLocationException;
19
import org.eclipse.jface.text.IDocument;
20
import org.eclipse.jface.text.contentassist.ICompletionProposal;
21
import org.eclipse.jface.text.contentassist.IContextInformation;
22
import org.eclipse.jpt.jpa.core.context.NamedQuery;
23
import org.eclipse.persistence.jpa.jpql.ContentAssistProposals;
24
import org.eclipse.persistence.jpa.jpql.ResultQuery;
25
import org.eclipse.swt.graphics.Image;
26
import org.eclipse.swt.graphics.Point;
27
28
/**
29
 * The concrete implementation of a {@link org.eclipse.jface.text.contentassist.ICompletionProposal
30
 * ICompletionProposal} that adds relevance and toggling the completion insertion property behavior.
31
 *
32
 * @version 3.0
33
 * @since 3.0
34
 * @author Pascal Filion
35
 */
36
final class JpqlCompletionProposal implements ICompletionProposal {
37
38
	private String actualQuery;
39
	private String additionalInfo;
40
	private ContentAssistProposals proposals;
41
	private int cursorOffset;
42
	private String displayString;
43
	private boolean escapeCharacters;
44
	private Image image;
45
	private String jpqlQuery;
46
	private NamedQuery namedQuery;
47
	private int offset;
48
	private int position;
49
	private String proposal;
50
	private ResultQuery result;
51
	private boolean toggleCompletion;
52
53
	JpqlCompletionProposal(ContentAssistProposals proposals,
54
	                       String proposal,
55
	                       String displayString,
56
	                       String additionalInfo,
57
	                       Image image,
58
	                       NamedQuery namedQuery,
59
	                       String actualQuery,
60
	                       String jpqlQuery,
61
	                       int offset,
62
	                       int position,
63
	                       int cursorOffset,
64
	                       boolean escapeCharacters) {
65
66
		super();
67
68
		this.image            = image;
69
		this.offset           = offset;
70
		this.position         = position;
71
		this.proposal         = proposal;
72
		this.jpqlQuery        = jpqlQuery;
73
		this.proposals        = proposals;
74
		this.namedQuery       = namedQuery;
75
		this.actualQuery      = actualQuery;
76
		this.cursorOffset     = cursorOffset;
77
		this.displayString    = displayString;
78
		this.additionalInfo   = additionalInfo;
79
		this.escapeCharacters = escapeCharacters;
80
	}
81
82
	/**
83
	 * {@inheritDoc}
84
	 */
85
	public void apply(IDocument document) {
86
		try {
87
			ResultQuery result = buildResult();
88
			document.replace(offset, actualQuery.length(), result.getQuery());
89
		}
90
		catch (BadLocationException e) {
91
			// Ignore
92
		}
93
	}
94
95
	private ResultQuery buildResult() {
96
		if (result == null) {
97
			if (escapeCharacters) {
98
				result = proposals.buildEscapedQuery(
99
					jpqlQuery,
100
					proposal,
101
					position,
102
					isCompletionInserts() ^ toggleCompletion
103
				);
104
			}
105
			else {
106
				result = proposals.buildQuery(
107
					jpqlQuery,
108
					proposal,
109
					position,
110
					isCompletionInserts() ^ toggleCompletion
111
				);
112
			}
113
		}
114
		return result;
115
	}
116
117
	/**
118
	 * {@inheritDoc}
119
	 */
120
	public String getAdditionalProposalInfo() {
121
		return additionalInfo;
122
	}
123
124
	/**
125
	 * {@inheritDoc}
126
	 */
127
	public IContextInformation getContextInformation() {
128
		return null; // Not needed, this is legacy API
129
	}
130
131
	/**
132
	 * {@inheritDoc}
133
	 */
134
	public String getDisplayString() {
135
		return displayString;
136
	}
137
138
	/**
139
	 * {@inheritDoc}
140
	 */
141
	public Image getImage() {
142
		return image;
143
	}
144
145
	/**
146
	 * {@inheritDoc}
147
	 */
148
	public Point getSelection(IDocument document) {
149
		ResultQuery result = buildResult();
150
		return new Point(offset + result.getPosition() + cursorOffset, 0);
151
	}
152
153
	private boolean isCompletionInserts() {
154
		IJavaProject javaProject = namedQuery.getJpaProject().getJavaProject();
155
		String value = PreferenceConstants.getPreference(PreferenceConstants.CODEASSIST_INSERT_COMPLETION, javaProject);
156
		return Boolean.valueOf(value);
157
	}
158
}
(-)src/org/eclipse/jpt/jpa/ui/internal/jpql/JpqlCompletionProposalComputer.java (+437 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
5
 * which accompanies this distribution.
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.ui.internal.jpql;
15
16
import java.util.ArrayList;
17
import java.util.Comparator;
18
import java.util.List;
19
import org.eclipse.core.runtime.IProgressMonitor;
20
import org.eclipse.jface.resource.ImageDescriptor;
21
import org.eclipse.jface.resource.ImageRegistry;
22
import org.eclipse.jpt.common.utility.internal.CollectionTools;
23
import org.eclipse.jpt.jpa.core.context.NamedQuery;
24
import org.eclipse.jpt.jpa.core.internal.jpql.JpaJpqlQueryHelper;
25
import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
26
import org.eclipse.jpt.jpa.ui.internal.JptUiIcons;
27
import org.eclipse.persistence.jpa.internal.jpql.WordParser;
28
import org.eclipse.persistence.jpa.internal.jpql.parser.Expression;
29
import org.eclipse.persistence.jpa.internal.jpql.parser.IdentifierRole;
30
import org.eclipse.persistence.jpa.internal.jpql.parser.JPQLExpression;
31
import org.eclipse.persistence.jpa.jpql.ContentAssistProposals;
32
import org.eclipse.persistence.jpa.jpql.spi.IEntity;
33
import org.eclipse.persistence.jpa.jpql.spi.IMapping;
34
import org.eclipse.swt.graphics.Image;
35
import org.eclipse.swt.widgets.Display;
36
37
import static org.eclipse.jpt.common.utility.internal.CollectionTools.*;
38
39
/**
40
 * The abstract definition of JPQL content assist support.
41
 *
42
 * @version 3.0
43
 * @since 3.0
44
 * @author Pascal Filion
45
 */
46
@SuppressWarnings({"nls", "restriction"})
47
abstract class JpqlCompletionProposalComputer<T> {
48
49
	/**
50
	 * The current value of the query element.
51
	 */
52
	String actualQuery;
53
54
	/**
55
	 * The provider of content assist items based on the position of the cursor within the JPQL query.
56
	 */
57
	ContentAssistProposals contentAssistProposals;
58
59
	/**
60
	 * The local registry containing the images used to display the possible proposals. The registry is
61
	 * disposed when the session ended.
62
	 */
63
	private ImageRegistry imageRegistry;
64
65
	/**
66
	 * The same value as {@link #actualQuery} or the modified query that was used by the Hermes parser.
67
	 */
68
	String jpqlQuery;
69
70
	/**
71
	 * The JPA model object that is used to access the Java project.
72
	 */
73
	NamedQuery namedQuery;
74
75
	/**
76
	 * The start position of the query within the document.
77
	 */
78
	int offset;
79
80
	/**
81
	 *
82
	 */
83
	private String partialWord;
84
85
	/**
86
	 * The position of the cursor within {@link #actualQuery}.
87
	 */
88
	int position;
89
90
	/**
91
	 * This helper is responsible to retrieve the possible proposals to complete or to add more
92
	 * information to a JPQL based on the position of the cursor.
93
	 */
94
	final JpaJpqlQueryHelper queryHelper;
95
96
	/**
97
	 * Creates a new <code>JpqlCompletionProposalComputer</code>.
98
	 */
99
	public JpqlCompletionProposalComputer() {
100
		super();
101
		queryHelper = new JpaJpqlQueryHelper();
102
	}
103
104
	/**
105
	 * Adds completion proposals for the abstract schema names that are possible proposals.
106
	 *
107
	 * @param proposals The list used to store the new completion proposals
108
	 */
109
	private void addAbstractSchemaNames(List<T> proposals) {
110
		for (IEntity abstractSchemaType : sortByNames(contentAssistProposals.abstractSchemaTypes())) {
111
			proposals.add(buildAbstractSchemaNameProposal(abstractSchemaType));
112
		}
113
	}
114
115
	/**
116
	 * Adds completion proposals for the identification variables that are possible proposals.
117
	 *
118
	 * @param proposals The list used to store the new completion proposals
119
	 */
120
	private void addIdentificationVariables(List<T> proposals) {
121
		for (String variable : sort(contentAssistProposals.identificationVariables())) {
122
			proposals.add(buildIdentificationVariableProposal(variable));
123
		}
124
	}
125
126
	/**
127
	 * Adds completion proposals for the JPQL identifiers that are possible proposals.
128
	 *
129
	 * @param proposals The list used to store the new completion proposals
130
	 */
131
	private void addIdentifiers(List<T> proposals) {
132
		for (String identifier : sort(contentAssistProposals.identifiers())) {
133
			proposals.add(buildIdentifierProposal(identifier));
134
		}
135
	}
136
137
	private String additionalInfo(String proposal) {
138
		return JpqlIdentifierMessages.localizedMessage(proposal);
139
	}
140
141
	/**
142
	 * Adds completion proposals for the state fields and association fields that are possible proposals.
143
	 *
144
	 * @param proposals The list used to store the new completion proposals
145
	 */
146
	private void addMappings(List<T> proposals) {
147
		for (IMapping mapping : sort(contentAssistProposals.mappings())) {
148
			proposals.add(buildMappingProposal(mapping));
149
		}
150
	}
151
152
	private T buildAbstractSchemaNameProposal(IEntity abstractSchemaType) {
153
		String proposal = abstractSchemaType.getName();
154
		return buildProposal(proposal, proposal, entityImage());
155
	}
156
157
	private Comparator<IEntity> buildEntityNameComparator() {
158
		return new Comparator<IEntity>() {
159
			public int compare(IEntity entity1, IEntity entity2) {
160
				return entity1.getName().compareTo(entity2.getName());
161
			}
162
		};
163
	}
164
165
	private String buildIdentificationVariableDisplayString(String identificationVariable) {
166
167
		IEntity abstractSchemaType = contentAssistProposals.getAbstractSchemaType(identificationVariable);
168
169
		if (abstractSchemaType != null) {
170
			StringBuilder sb = new StringBuilder();
171
			sb.append(identificationVariable);
172
			sb.append(" : ");
173
			sb.append(abstractSchemaType.getName());
174
			identificationVariable = sb.toString();
175
		}
176
177
		return identificationVariable;
178
	}
179
180
	private T buildIdentificationVariableProposal(String proposal) {
181
		return buildProposal(
182
			proposal,
183
			buildIdentificationVariableDisplayString(proposal),
184
			identificationVariableImage()
185
		);
186
	}
187
188
	private T buildIdentifierProposal(String proposal) {
189
190
		String additionalInfo = additionalInfo(proposal);
191
		IdentifierRole role = JPQLExpression.identifierRole(proposal);
192
		boolean realFunction = (role == IdentifierRole.FUNCTION) && isRealFunction(proposal);
193
		int cursorOffset = 0;
194
195
		// There is at least one letter before the cursor, if the setting "Match First Letter Case"
196
		// is true, then match the case of the JPQL identifier with the first character
197
		if ((partialWord.length() > 0) && shouldMatchFirstCharacterCase()) {
198
			if (Character.isLowerCase(partialWord.charAt(0))) {
199
				proposal = proposal.toLowerCase();
200
			}
201
		}
202
		// Convert the case of the JPQL identifier based on the setting
203
		else if (shouldUseLowercaseIdentifiers()) {
204
			proposal = proposal.toLowerCase();
205
		}
206
207
		// For JPQL function, we add () to the display string, example: AVG()
208
		// But for TRUE, FALSE, etc, we don't add ()
209
		if (realFunction) {
210
			proposal += "()";
211
			cursorOffset--;
212
		}
213
214
		return buildProposal(
215
			proposal,
216
			proposal,
217
			additionalInfo,
218
			identifierImage(realFunction),
219
			cursorOffset
220
		);
221
	}
222
223
	private T buildMappingProposal(IMapping mapping) {
224
		String proposal = mapping.getName();
225
		return buildProposal(proposal, proposal, mappingImage(mapping));
226
	}
227
228
	private T buildProposal(String proposal, String displayString, Image image) {
229
		return buildProposal(proposal, displayString, null, image, 0);
230
	}
231
232
	/**
233
	 * Creates a new completion proposal for the given proposal.
234
	 *
235
	 * @param proposal A valid proposal that can be inserted into the query
236
	 * @param displayString The human readable string of the proposal
237
	 * @param additionalInfo Optional additional information about the proposal. The additional
238
	 * information will be presented to assist the user in deciding if the selected proposal is the
239
	 * desired choice
240
	 * @param image The image that represents the proposal
241
	 * @param cursorOffset An offset that moves the cursor backward or forward after it is adjusted
242
	 * based on the given proposal
243
	 * @return The completion proposal
244
	 */
245
	abstract T buildProposal(String proposal,
246
	                         String displayString,
247
	                         String additionalInfo,
248
	                         Image image,
249
	                         int cursorOffset);
250
251
	/**
252
	 * Creates the list of completion proposals based on the current content of the JPQL query and at
253
	 * the specified position.
254
	 *
255
	 * @param namedQuery The model object used to access the application metadata information
256
	 * @param actualQuery The model object may sometimes be out of sync with the actual content, the
257
	 * actual query is required for proper content assist
258
	 * @param offset The beginning of the string within the document
259
	 * @param position The position of the cursor within the query, which starts at the beginning of
260
	 * that query and not the document
261
	 * @return The list of completion proposals
262
	 */
263
	final List<T> buildProposals(NamedQuery namedQuery, String actualQuery, int offset, int position) {
264
265
		this.offset      = offset;
266
		this.actualQuery = actualQuery;
267
		this.namedQuery  = namedQuery;
268
269
		// It's possible the string has literal representation of the escape characters, if required,
270
		// convert them into actual escape characters and adjust the position accordingly
271
		int[] positions  = { position };
272
		this.jpqlQuery   = modifyJpqlQuery(actualQuery, positions);
273
		this.position    = positions[0];
274
		this.partialWord = partialWord();
275
276
		// Gather the possible proposals
277
		this.queryHelper.setQuery(namedQuery, jpqlQuery);
278
		this.contentAssistProposals = queryHelper.buildContentAssistProposals(positions[0]);
279
		this.queryHelper.dispose();
280
281
		// Create the proposals for those proposals
282
		List<T> proposals = new ArrayList<T>();
283
		addAbstractSchemaNames    (proposals);
284
		addIdentificationVariables(proposals);
285
		addIdentifiers            (proposals);
286
		addMappings               (proposals);
287
288
		return proposals;
289
	}
290
291
	final void checkCanceled(IProgressMonitor monitor) throws InterruptedException {
292
		if (monitor.isCanceled()) {
293
			throw new InterruptedException();
294
		}
295
	}
296
297
	/**
298
	 * Clears the information used to retrieve the content assist proposals.
299
	 */
300
	final void clearInformation() {
301
302
		offset      = -1;
303
		position    = -1;
304
		actualQuery = null;
305
		namedQuery  = null;
306
		partialWord = null;
307
		contentAssistProposals = null;
308
	}
309
310
	private Image entityImage() {
311
		return getImage(JptUiIcons.ENTITY);
312
	}
313
314
	/**
315
	 * Returns the reason why this computer was unable to produce any completion proposals or
316
	 * context information.
317
	 *
318
	 * @return An error message or <code>null</code> if no error occurred
319
	 */
320
	public String getErrorMessage() {
321
		return null;
322
	}
323
324
	private Image getImage(String key) {
325
		ImageRegistry imageRegistry = getImageRegistry();
326
		Image image = imageRegistry.get(key);
327
		if (image == null) {
328
			imageRegistry.put(key, getImageDescriptor(key));
329
			image = imageRegistry.get(key);
330
		}
331
		return image;
332
	}
333
334
	private ImageDescriptor getImageDescriptor(String key) {
335
		return JptJpaUiPlugin.getImageDescriptor(key);
336
	}
337
338
	private ImageRegistry getImageRegistry() {
339
		if (imageRegistry == null) {
340
			imageRegistry = new ImageRegistry(Display.getCurrent());
341
		}
342
		return imageRegistry;
343
	}
344
345
	private Image identificationVariableImage() {
346
		return getImage(JptUiIcons.JPQL_VARIABLE);
347
	}
348
349
	private Image identifierImage(boolean function) {
350
351
		if (function) {
352
			return getImage(JptUiIcons.JPQL_FUNCTION);
353
		}
354
355
		return getImage(JptUiIcons.JPQL_IDENTIFIER);
356
	}
357
358
	private boolean isRealFunction(String identifier) {
359
		return identifier != Expression.TRUE         &&
360
		       identifier != Expression.FALSE        &&
361
		       identifier != Expression.NULL         &&
362
		       identifier != Expression.CURRENT_DATE &&
363
		       identifier != Expression.CURRENT_TIME &&
364
		       identifier != Expression.CURRENT_TIMESTAMP;
365
	}
366
367
	private Image mappingImage(IMapping mapping) {
368
		switch (mapping.getMappingType()) {
369
			case BASIC:               return getImage(JptUiIcons.BASIC);
370
			case BASIC_COLLECTION:    return getImage(JptUiIcons.ELEMENT_COLLECTION);
371
			case BASIC_MAP:           return getImage(JptUiIcons.ELEMENT_COLLECTION);
372
			case ELEMENT_COLLECTION:  return getImage(JptUiIcons.ELEMENT_COLLECTION);
373
			case EMBEDDED:            return getImage(JptUiIcons.EMBEDDED);
374
			case EMBEDDED_ID:         return getImage(JptUiIcons.EMBEDDED_ID);
375
			case ID:                  return getImage(JptUiIcons.ID);
376
			case MANY_TO_MANY:        return getImage(JptUiIcons.MANY_TO_MANY);
377
			case MANY_TO_ONE:         return getImage(JptUiIcons.MANY_TO_ONE);
378
			case ONE_TO_MANY:         return getImage(JptUiIcons.ONE_TO_MANY);
379
			case ONE_TO_ONE:          return getImage(JptUiIcons.ONE_TO_ONE);
380
			case TRANSFORMATION:      return getImage(JptUiIcons.BASIC);      // TODO
381
			case VARIABLE_ONE_TO_ONE: return getImage(JptUiIcons.ONE_TO_ONE); // TODO
382
			case VERSION:             return getImage(JptUiIcons.VERSION);
383
			default:                  return getImage(JptUiIcons.TRANSIENT);
384
		}
385
	}
386
387
	/**
388
	 * In some context, the given JPQL query needs to be modified before it is parsed.
389
	 *
390
	 * @param jpqlQuery The JPQL query to keep unchanged or to modify before parsing it
391
	 * @param position The position of the cursor within the JPQL query, which needs to be updated if
392
	 * the query is modified
393
	 * @return The given JPQL query or a modified version that will be parsed
394
	 */
395
	String modifyJpqlQuery(String jpqlQuery, int[] position) {
396
		return jpqlQuery;
397
	}
398
399
	private String partialWord() {
400
		WordParser wordParser = new WordParser(jpqlQuery);
401
		wordParser.setPosition(position);
402
		return wordParser.partialWord();
403
	}
404
405
	/**
406
	 * Informs the computer that a content assist session has ended.
407
	 */
408
	public void sessionEnded() {
409
410
		queryHelper.disposeProvider();
411
		clearInformation();
412
413
		if (imageRegistry != null) {
414
			imageRegistry.dispose();
415
		}
416
	}
417
418
	/**
419
	 * Informs the computer that a content assist session has started.
420
	 */
421
	public void sessionStarted() {
422
		// Nothing to do
423
	}
424
425
	private boolean shouldMatchFirstCharacterCase() {
426
		return JptJpaUiPlugin.instance().getPreferenceStore().getBoolean(JptJpaUiPlugin.JPQL_IDENTIFIER_MATCH_FIRST_CHARACTER_CASE_PREF_KEY);
427
	}
428
429
	private boolean shouldUseLowercaseIdentifiers() {
430
		String value = JptJpaUiPlugin.instance().getPreferenceStore().getString(JptJpaUiPlugin.JPQL_IDENTIFIER_CASE_PREF_KEY);
431
		return JptJpaUiPlugin.JPQL_IDENTIFIER_LOWERCASE_PREF_VALUE.equals(value);
432
	}
433
434
	private Iterable<IEntity> sortByNames(Iterable<IEntity> abstractSchemaTypes) {
435
		return CollectionTools.sort(abstractSchemaTypes, buildEntityNameComparator());
436
	}
437
}
(-)src/org/eclipse/jpt/jpa/ui/internal/jpql/JpqlIdentifierMessages.java (+186 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
5
 * which accompanies this distribution.
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.ui.internal.jpql;
15
16
import java.lang.reflect.Field;
17
import java.util.HashMap;
18
import java.util.Map;
19
import org.eclipse.osgi.util.NLS;
20
import org.eclipse.persistence.jpa.internal.jpql.parser.Expression;
21
22
/**
23
 * The localized messages describing the JPQL identifiers.
24
 *
25
 * @version 3.0
26
 * @since 3.0
27
 * @author Pascal Filion
28
 */
29
@SuppressWarnings({"nls", "restriction"})
30
final class JpqlIdentifierMessages extends NLS {
31
32
	// JPA 1.0 identifiers
33
	public static String ABS;
34
	public static String ALL;
35
	public static String ANY;
36
	public static String ASC;
37
	public static String AVG;
38
	public static String BETWEEN;
39
	public static String BOTH;
40
	public static String CONCAT;
41
	public static String COUNT;
42
	public static String CURRENT_DATE;
43
	public static String CURRENT_TIME;
44
	public static String CURRENT_TIMESTAMP;
45
	public static String DELETE_FROM;
46
	public static String DESC;
47
	public static String DISTINCT;
48
	public static String ESCAPE;
49
	public static String EXISTS;
50
	public static String FROM;
51
	public static String GROUP_BY;
52
	public static String HAVING;
53
	public static String IN;
54
	public static String IS_EMPTY;
55
	public static String IS_NULL;
56
	public static String JOIN;
57
	public static String JOIN_FETCH;
58
	public static String LEADING;
59
	public static String LENGTH;
60
	public static String LIKE;
61
	public static String LOCATE;
62
	public static String LOWER;
63
	public static String MAX;
64
	public static String MEMBER;
65
	public static String MIN;
66
	public static String MOD;
67
	public static String NEW;
68
	public static String OBJECT;
69
	public static String ORDER_BY;
70
	public static String SELECT;
71
	public static String SIZE;
72
	public static String SOME;
73
	public static String SQRT;
74
	public static String SUBSTRING;
75
	public static String SUM;
76
	public static String TRAILING;
77
	public static String TRIM;
78
	public static String UPDATE;
79
	public static String UPPER;
80
	public static String WHERE;
81
82
	// JPA 2.0 identifiers
83
	public static String CASE;
84
	public static String COALESCE;
85
	public static String ENTRY;
86
	public static String INDEX;
87
	public static String KEY;
88
	public static String NULLIF;
89
	public static String TYPE;
90
	public static String VALUE;
91
92
	// EclipseLink identifiers
93
	public static String FUNC;
94
	public static String TREAT;
95
96
	// Reserved JPQL identifiers
97
	public static String BIT_LENGTH;
98
	public static String CHAR_LENGTH;
99
	public static String CHARACTER_LENGTH;
100
	public static String CLASS;
101
	public static String POSITION;
102
	public static String UNKNOWN;
103
104
	static {
105
		NLS.initializeMessages("jpt_ui_jpql_identifiers", JpqlIdentifierMessages.class);
106
	}
107
108
	JpqlIdentifierMessages() {
109
		super();
110
		throw new UnsupportedOperationException();
111
	}
112
113
	private static Map<String, String> registeredIdentifers;
114
115
	private static Map<String, String> buildRegisteredIdentifers() {
116
117
		Map<String, String> identifiers = new HashMap<String, String>();
118
119
		identifiers.put(Expression.IS_NOT_EMPTY,  Expression.IS_EMPTY);
120
		identifiers.put(Expression.IS_NOT_NULL,   Expression.IS_NULL);
121
		identifiers.put(Expression.MEMBER_OF,     Expression.MEMBER);
122
		identifiers.put(Expression.NOT_IN,        Expression.IN);
123
		identifiers.put(Expression.NOT_BETWEEN,   Expression.BETWEEN);
124
		identifiers.put(Expression.NOT_MEMBER,    Expression.MEMBER);
125
		identifiers.put(Expression.NOT_MEMBER_OF, Expression.MEMBER);
126
127
		identifiers.put(Expression.INNER_JOIN,      Expression.JOIN);
128
		identifiers.put(Expression.LEFT_JOIN,       Expression.JOIN);
129
		identifiers.put(Expression.LEFT_OUTER_JOIN, Expression.JOIN);
130
131
		identifiers.put(Expression.INNER_JOIN_FETCH,      Expression.JOIN_FETCH);
132
		identifiers.put(Expression.LEFT_JOIN_FETCH,       Expression.JOIN_FETCH);
133
		identifiers.put(Expression.LEFT_OUTER_JOIN_FETCH, Expression.JOIN_FETCH);
134
135
		return identifiers;
136
	}
137
138
	/**
139
	 * Converts the given JPQL identifier to the shortest form that is used to map the localized
140
	 * message. If the identifier is <b>NOT MEMBER</b> for instance, then it needs to be converted
141
	 * to <b>MEMBER</b> since that's the identifier used to map the localize message.
142
	 *
143
	 * @param identifier The JPQL identifier to convert, if needed
144
	 * @return Either the given JPQL identifier or its counterpart that is used to map the localized
145
	 * message
146
	 */
147
	private static String convertIdentifier(String identifier) {
148
		identifier = registeredIdentifer(identifier);
149
		identifier = identifier.replace(" ", "_");
150
		return identifier;
151
	}
152
153
	/**
154
	 * Retrieves the localized message for the given string value, if it's a JPQL identifier.
155
	 *
156
	 * @param identifier The JPQL identifier for which its localized description is needed
157
	 * @return The localized message describing the given JPQL identifier or <code>null</code> if the
158
	 * given choice is not an identifier
159
	 */
160
	static String localizedMessage(String identifier) {
161
		try {
162
			identifier = convertIdentifier(identifier);
163
			Field constant = JpqlIdentifierMessages.class.getField(identifier);
164
			return (String) constant.get(null);
165
		}
166
		catch (Exception e) {
167
			// The choice is not a JPQL identifier
168
			return null;
169
		}
170
	}
171
172
	private static String registeredIdentifer(String identifier) {
173
		String another = registeredIdentifers().get(identifier);
174
		if (another != null) {
175
			return another;
176
		}
177
		return identifier;
178
	}
179
180
	private static Map<String, String> registeredIdentifers() {
181
		if (registeredIdentifers == null) {
182
			registeredIdentifers = buildRegisteredIdentifers();
183
		}
184
		return registeredIdentifers;
185
	}
186
}
(-)src/org/eclipse/jpt/jpa/ui/internal/jpql/TextTransferHandler.java (+228 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
5
 * which accompanies this distribution.
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.ui.internal.jpql;
15
16
import org.eclipse.jface.text.IUndoManager;
17
import org.eclipse.jpt.common.utility.internal.StringTools;
18
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.custom.StyledText;
20
import org.eclipse.swt.dnd.Clipboard;
21
import org.eclipse.swt.dnd.TextTransfer;
22
import org.eclipse.swt.dnd.TransferData;
23
import org.eclipse.swt.events.MenuEvent;
24
import org.eclipse.swt.events.MenuListener;
25
import org.eclipse.swt.events.SelectionAdapter;
26
import org.eclipse.swt.events.SelectionEvent;
27
import org.eclipse.swt.events.SelectionListener;
28
import org.eclipse.swt.graphics.Point;
29
import org.eclipse.swt.widgets.Menu;
30
import org.eclipse.swt.widgets.MenuItem;
31
import org.eclipse.ui.internal.WorkbenchMessages;
32
33
/**
34
 * This handler adds a context menu onto a {@link StyledText} which have the default actions dealing
35
 * with text editing: Undo | Cut, Copy, Paste, Delete | Select All.
36
 *
37
 * @version 3.0
38
 * @since 3.0
39
 * @author Pascal Filion
40
 */
41
@SuppressWarnings("restriction")
42
public final class TextTransferHandler {
43
44
	private MenuItem copyMenuItem;
45
	private MenuItem cutMenuItem;
46
	private MenuItem deleteMenuItem;
47
	private MenuItem pasteMenuItem;
48
	private Menu popup;
49
	private MenuItem selectAllMenuItem;
50
	private StyledText styledText;
51
	private IUndoManager undoManager;
52
	private MenuItem undoMenuItem;
53
54
	private TextTransferHandler(StyledText styledText, IUndoManager undoManager) {
55
		super();
56
		this.styledText  = styledText;
57
		this.undoManager = undoManager;
58
	}
59
60
	/**
61
	 * Installs a context menu onto the given {@link StyledText} which have the default actions
62
	 * dealing with text editing: Undo | Cut, Copy, Paste, Delete | Select All.
63
	 *
64
	 * @param styledText The widget for which a context menu will be added
65
	 * @param undoManager The manager to undo keystrokes
66
	 */
67
	public static void installContextMenu(StyledText styledText, IUndoManager undoManager) {
68
		TextTransferHandler handler = new TextTransferHandler(styledText, undoManager);
69
		handler.installPopup();
70
	}
71
72
	private SelectionAdapter buildCopySelectionListener() {
73
		return new SelectionAdapter() {
74
			@Override
75
			public void widgetSelected(SelectionEvent e) {
76
				styledText.copy();
77
			}
78
		};
79
	}
80
81
	private SelectionListener buildCutSelectionListener() {
82
		return new SelectionAdapter() {
83
			@Override
84
			public void widgetSelected(SelectionEvent e) {
85
				styledText.cut();
86
			}
87
		};
88
	}
89
90
	private SelectionListener buildDeleteSelectionListener() {
91
		return new SelectionAdapter() {
92
			@Override
93
			public void widgetSelected(SelectionEvent e) {
94
				Point selection = styledText.getSelection();
95
				styledText.replaceTextRange(selection.x, selection.y - selection.x, StringTools.EMPTY_STRING);
96
			}
97
		};
98
	}
99
100
	private MenuListener buildMenuListener() {
101
		return new MenuListener() {
102
			public void menuHidden(MenuEvent e) {
103
			}
104
			public void menuShown(MenuEvent e) {
105
				update();
106
			}
107
		};
108
	}
109
110
	private SelectionListener buildPasteSelectionListener() {
111
		return new SelectionAdapter() {
112
			@Override
113
			public void widgetSelected(SelectionEvent e) {
114
				styledText.paste();
115
			}
116
		};
117
	}
118
119
	private SelectionListener buildSelectAllSelectionListener() {
120
		return new SelectionAdapter() {
121
			@Override
122
			public void widgetSelected(SelectionEvent e) {
123
				styledText.selectAll();
124
			}
125
		};
126
	}
127
128
	private SelectionListener buildUndoSelectionListener() {
129
		return new SelectionAdapter() {
130
			@Override
131
			public void widgetSelected(SelectionEvent e) {
132
				undoManager.undo();
133
			}
134
		};
135
	}
136
137
	private boolean canCopy() {
138
		Point selection = styledText.getSelection();
139
		return selection.x != selection.y;
140
	}
141
142
	private boolean canCut() {
143
		Point selection = styledText.getSelection();
144
		return selection.x != selection.y;
145
	}
146
147
	private boolean canDelete() {
148
		Point selection = styledText.getSelection();
149
		return selection.x != selection.y;
150
	}
151
152
	private boolean canPaste() {
153
154
		Clipboard clipboard = new Clipboard(styledText.getDisplay());
155
		boolean canPaste = false;
156
157
		for (TransferData data : clipboard.getAvailableTypes()) {
158
			if (TextTransfer.getInstance().isSupportedType(data)) {
159
				canPaste = true;
160
				break;
161
			}
162
		}
163
164
		clipboard.dispose();
165
		return canPaste;
166
	}
167
168
	private boolean canSelectAll() {
169
		Point selection = styledText.getSelection();
170
		String text = styledText.getText();
171
		return (selection.y - selection.x) != text.length();
172
	}
173
174
	private void installPopup() {
175
176
		popup = new Menu(styledText.getShell(), SWT.POP_UP);
177
		popup.addMenuListener(buildMenuListener());
178
		styledText.setMenu(popup);
179
180
		populatePopup();
181
	}
182
183
	private void populatePopup() {
184
185
		// Undo
186
		undoMenuItem = new MenuItem(popup, SWT.PUSH);
187
		undoMenuItem.setText(WorkbenchMessages.Workbench_undo);
188
		undoMenuItem.addSelectionListener(buildUndoSelectionListener());
189
190
		new MenuItem(popup, SWT.SEPARATOR);
191
192
		// Cut
193
		cutMenuItem = new MenuItem(popup, SWT.PUSH);
194
		cutMenuItem.setText(WorkbenchMessages.Workbench_cut);
195
		cutMenuItem.addSelectionListener(buildCutSelectionListener());
196
197
		// Copy
198
		copyMenuItem = new MenuItem(popup, SWT.PUSH);
199
		copyMenuItem.setText(WorkbenchMessages.Workbench_copy);
200
		copyMenuItem.addSelectionListener(buildCopySelectionListener());
201
202
		// Paste
203
		pasteMenuItem = new MenuItem(popup, SWT.PUSH);
204
		pasteMenuItem.setText(WorkbenchMessages.Workbench_paste);
205
		pasteMenuItem.addSelectionListener(buildPasteSelectionListener());
206
207
		// Delete
208
		deleteMenuItem = new MenuItem(popup, SWT.PUSH);
209
		deleteMenuItem.setText(WorkbenchMessages.Workbench_delete);
210
		deleteMenuItem.addSelectionListener(buildDeleteSelectionListener());
211
212
		new MenuItem(popup, SWT.SEPARATOR);
213
214
		// Select All
215
		selectAllMenuItem = new MenuItem(popup, SWT.PUSH);
216
		selectAllMenuItem.setText(WorkbenchMessages.Workbench_selectAll);
217
		selectAllMenuItem.addSelectionListener(buildSelectAllSelectionListener());
218
	}
219
220
	private void update() {
221
		deleteMenuItem   .setEnabled(canDelete());
222
		copyMenuItem     .setEnabled(canCopy());
223
		cutMenuItem      .setEnabled(canCut());
224
		pasteMenuItem    .setEnabled(canPaste());
225
		selectAllMenuItem.setEnabled(canSelectAll());
226
		undoMenuItem     .setEnabled(undoManager.undoable());
227
	}
228
}
(-)src/org/eclipse/jpt/jpa/ui/internal/preferences/JpaPreferencesPage.java (-10 / +143 lines)
Lines 9-41 Link Here
9
 ******************************************************************************/
9
 ******************************************************************************/
10
package org.eclipse.jpt.jpa.ui.internal.preferences;
10
package org.eclipse.jpt.jpa.ui.internal.preferences;
11
11
12
import org.eclipse.jface.dialogs.Dialog;
13
import org.eclipse.jface.dialogs.IDialogConstants;
12
import org.eclipse.jface.preference.PreferencePage;
14
import org.eclipse.jface.preference.PreferencePage;
13
import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
15
import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
14
import org.eclipse.jpt.jpa.ui.internal.JptUiMessages;
16
import org.eclipse.jpt.jpa.ui.internal.JptUiMessages;
15
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.events.SelectionAdapter;
19
import org.eclipse.swt.events.SelectionEvent;
20
import org.eclipse.swt.events.SelectionListener;
16
import org.eclipse.swt.layout.GridData;
21
import org.eclipse.swt.layout.GridData;
17
import org.eclipse.swt.layout.GridLayout;
22
import org.eclipse.swt.layout.GridLayout;
23
import org.eclipse.swt.widgets.Button;
18
import org.eclipse.swt.widgets.Composite;
24
import org.eclipse.swt.widgets.Composite;
19
import org.eclipse.swt.widgets.Control;
25
import org.eclipse.swt.widgets.Control;
26
import org.eclipse.swt.widgets.Group;
20
import org.eclipse.swt.widgets.Label;
27
import org.eclipse.swt.widgets.Label;
21
import org.eclipse.ui.IWorkbench;
28
import org.eclipse.ui.IWorkbench;
22
import org.eclipse.ui.IWorkbenchPreferencePage;
29
import org.eclipse.ui.IWorkbenchPreferencePage;
23
30
24
/**
31
/**
25
 * This is the root of the Java Persistence preferences hierarchy in the IDE
32
 * This is the root of the Java Persistence preferences hierarchy in the IDE preferences dialog.
26
 * preferences dialog.
27
 * <p>
33
 * <p>
28
 * Structure:
34
 * Structure:
29
 * <p>
35
 * <p>
30
 * Java Persistence<br>
36
 * JPA<br>
31
 *  |- Errors/Warnings
37
 *  |- Errors/Warnings
32
 *
38
 *
33
 * @version 2.2
39
 * @version 3.0
34
 * @since 2.2
40
 * @since 3.0
35
 */
41
 */
36
public class JpaPreferencesPage extends PreferencePage
42
public class JpaPreferencesPage extends PreferencePage
37
                                implements IWorkbenchPreferencePage {
43
                                implements IWorkbenchPreferencePage {
38
44
45
	private boolean lowercase;
46
	private Button lowerCaseRadioButton;
47
	private boolean matchFirstCharacterCase;
48
	private Button matchFirstCharacterCaseCheckBox;
49
	private Button upperCaseRadioButton;
50
39
	/**
51
	/**
40
	 * Creates a new <code>JpaPreferencesPage</code>.
52
	 * Creates a new <code>JpaPreferencesPage</code>.
41
	 */
53
	 */
Lines 43-61 Link Here
43
		super();
55
		super();
44
	}
56
	}
45
57
58
	private void addJpqlEditorGroup(Composite parent) {
59
60
		// JPQL Editing group box
61
		Group group = new Group(parent, SWT.NONE);
62
		group.setText(JptUiMessages.JpaPreferencesPage_jpqlEditor);
63
		group.setLayout(new GridLayout());
64
		group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
65
66
		// Top description
67
		Label description = new Label(group, SWT.NONE);
68
		description.setText(JptUiMessages.JpaPreferencesPage_jpqlEditor_description);
69
70
		// Uppercase radio button
71
		lowerCaseRadioButton = new Button(group, SWT.RADIO);
72
		lowerCaseRadioButton.setText(JptUiMessages.JpaPreferencesPage_jpqlEditor_lowerCaseRadioButton);
73
		lowerCaseRadioButton.addSelectionListener(buildLowercaseSelectionListener());
74
		lowerCaseRadioButton.setSelection(lowercase);
75
76
		// Uppercase radio button
77
		upperCaseRadioButton = new Button(group, SWT.RADIO);
78
		upperCaseRadioButton.setText(JptUiMessages.JpaPreferencesPage_jpqlEditor_upperCaseRadioButton);
79
		upperCaseRadioButton.addSelectionListener(buildUppercaseSelectionListener());
80
		upperCaseRadioButton.setSelection(!lowercase);
81
82
		new Label(group, SWT.NONE);
83
84
		// Match Case of First Letter check box
85
		matchFirstCharacterCaseCheckBox = new Button(group, SWT.CHECK);
86
		matchFirstCharacterCaseCheckBox.setText(JptUiMessages.JpaPreferencesPage_jpqlEditor_matchFirstCharacterCaseRadioButton);
87
		matchFirstCharacterCaseCheckBox.addSelectionListener(buildMatchFirstCharacterCaseSelectionListener());
88
		matchFirstCharacterCaseCheckBox.setSelection(matchFirstCharacterCase);
89
	}
90
91
	private SelectionListener buildLowercaseSelectionListener() {
92
		return new SelectionAdapter() {
93
			@Override
94
			public void widgetSelected(SelectionEvent e) {
95
				Button button = (Button) e.widget;
96
				lowercase = button.getSelection();
97
			}
98
		};
99
	}
100
101
	private SelectionListener buildMatchFirstCharacterCaseSelectionListener() {
102
		return new SelectionAdapter() {
103
			@Override
104
			public void widgetSelected(SelectionEvent e) {
105
				Button button = (Button) e.widget;
106
				matchFirstCharacterCase = button.getSelection();
107
			}
108
		};
109
	}
110
111
	private SelectionListener buildUppercaseSelectionListener() {
112
		return new SelectionAdapter() {
113
			@Override
114
			public void widgetSelected(SelectionEvent e) {
115
				Button button = (Button) e.widget;
116
				lowercase = !button.getSelection();
117
			}
118
		};
119
	}
120
46
	/**
121
	/**
47
	 * {@inheritDoc}
122
	 * {@inheritDoc}
48
	 */
123
	 */
49
	@Override
124
	@Override
50
	protected Control createContents(Composite parent) {
125
	protected Control createContents(Composite parent) {
126
		initializeDialogUnits(parent);
127
51
		parent = new Composite(parent, SWT.NONE);
128
		parent = new Composite(parent, SWT.NONE);
52
		parent.setLayout(new GridLayout(1, false));
129
		GridLayout layout = new GridLayout(1, false);
130
		layout.marginWidth = 0;
131
		layout.marginHeight = 0;
132
		layout.verticalSpacing = convertVerticalDLUsToPixels(10);
133
		layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
134
		parent.setLayout(layout);
135
136
		Label description = new Label(parent, SWT.NONE);
137
		description.setText(JptUiMessages.JpaPreferencesPage_description);
53
138
54
		// Message label
139
		addJpqlEditorGroup(parent);
55
		Label label = new Label(parent, SWT.NONE);
56
		label.setText(JptUiMessages.JpaPreferencesPage_Description);
57
		label.setData(new GridData(GridData.BEGINNING, GridData.BEGINNING, true, true));
58
140
141
		Dialog.applyDialogFont(parent);
59
		return parent;
142
		return parent;
60
	}
143
	}
61
144
Lines 64-68 Link Here
64
	 */
147
	 */
65
	public void init(IWorkbench workbench) {
148
	public void init(IWorkbench workbench) {
66
		setPreferenceStore(JptJpaUiPlugin.instance().getPreferenceStore());
149
		setPreferenceStore(JptJpaUiPlugin.instance().getPreferenceStore());
150
		lowercase = shouldUseLowercaseIdentifiers();
151
		matchFirstCharacterCase = shouldMatchFirstCharacterCase();
152
	}
153
154
	private boolean isDefaultJpqlIdentifierLowercase() {
155
		String value = getPreferenceStore().getDefaultString(JptJpaUiPlugin.JPQL_IDENTIFIER_CASE_PREF_KEY);
156
		return JptJpaUiPlugin.JPQL_IDENTIFIER_LOWERCASE_PREF_VALUE.equals(value);
157
	}
158
159
	private String jpqlIdentifierPreferenceValue() {
160
		return lowercase ? JptJpaUiPlugin.JPQL_IDENTIFIER_LOWERCASE_PREF_VALUE : JptJpaUiPlugin.JPQL_IDENTIFIER_UPPERCASE_PREF_VALUE;
161
	}
162
163
	/**
164
	 * {@inheritDoc}
165
	 */
166
	@Override
167
	protected void performDefaults() {
168
169
		lowercase = isDefaultJpqlIdentifierLowercase();
170
		matchFirstCharacterCase = shouldDefaultMatchFirstCharacterCase();
171
172
		lowerCaseRadioButton.setSelection(lowercase);
173
		upperCaseRadioButton.setSelection(!lowercase);
174
		matchFirstCharacterCaseCheckBox.setSelection(matchFirstCharacterCase);
175
176
		super.performDefaults();
177
	}
178
179
	/**
180
	 * {@inheritDoc}
181
	 */
182
	@Override
183
	public boolean performOk() {
184
		getPreferenceStore().setValue(JptJpaUiPlugin.JPQL_IDENTIFIER_CASE_PREF_KEY, jpqlIdentifierPreferenceValue());
185
		getPreferenceStore().setValue(JptJpaUiPlugin.JPQL_IDENTIFIER_MATCH_FIRST_CHARACTER_CASE_PREF_KEY, matchFirstCharacterCase);
186
		return super.performOk();
187
	}
188
189
	private boolean shouldDefaultMatchFirstCharacterCase() {
190
		return getPreferenceStore().getDefaultBoolean(JptJpaUiPlugin.JPQL_IDENTIFIER_MATCH_FIRST_CHARACTER_CASE_PREF_KEY);
191
	}
192
193
	private boolean shouldMatchFirstCharacterCase() {
194
		return getPreferenceStore().getBoolean(JptJpaUiPlugin.JPQL_IDENTIFIER_MATCH_FIRST_CHARACTER_CASE_PREF_KEY);
195
	}
196
197
	private boolean shouldUseLowercaseIdentifiers() {
198
		String value = getPreferenceStore().getString(JptJpaUiPlugin.JPQL_IDENTIFIER_CASE_PREF_KEY);
199
		return JptJpaUiPlugin.JPQL_IDENTIFIER_LOWERCASE_PREF_VALUE.equals(value);
67
	}
200
	}
68
}
201
}
(-)src/org/eclipse/jpt/jpa/ui/internal/preferences/JpaProblemSeveritiesPage.java (-21 / +22 lines)
Lines 73-85 Link Here
73
73
74
	/**
74
	/**
75
	 * Default severity levels are stored here,  ERROR is the default default so only need
75
	 * Default severity levels are stored here,  ERROR is the default default so only need
76
	 * to include WARNING, INFO, IGNORE in this Map. These will be displayed if neither the project 
76
	 * to include WARNING, INFO, IGNORE in this Map. These will be displayed if neither the project
77
	 * or workspace preference applies.
77
	 * or workspace preference applies.
78
	 * <br> key is the preferenceKey which is also the validation message key @see JpaValidationMessages.
78
	 * <br> key is the preferenceKey which is also the validation message key @see JpaValidationMessages.
79
	 * <br> value is a severity level - @see JpaValidationPreferences#ERROR WARNING INFO IGNORE
79
	 * <br> value is a severity level - @see JpaValidationPreferences#ERROR WARNING INFO IGNORE
80
	 */
80
	 */
81
	private Map<String, String> defaultSeverities;
81
	private Map<String, String> defaultSeverities;
82
	
82
83
	/**
83
	/**
84
	 * The list of <code>Combo</code>s is cached in order to perform a revert of
84
	 * The list of <code>Combo</code>s is cached in order to perform a revert of
85
	 * the properties.
85
	 * the properties.
Lines 335-341 Link Here
335
	private void addAttributeLevelCategory(Composite parent) {
335
	private void addAttributeLevelCategory(Composite parent) {
336
336
337
		parent = addExpandableSection(parent, JptUiValidationPreferenceMessages.ATTRIBUTE_LEVEL_CATEGORY);
337
		parent = addExpandableSection(parent, JptUiValidationPreferenceMessages.ATTRIBUTE_LEVEL_CATEGORY);
338
		
338
339
		addLabeledCombo(
339
		addLabeledCombo(
340
			parent, JptUiValidationPreferenceMessages.PERSISTENT_ATTRIBUTE_UNSPECIFIED_NAME,
340
			parent, JptUiValidationPreferenceMessages.PERSISTENT_ATTRIBUTE_UNSPECIFIED_NAME,
341
			JpaValidationMessages.PERSISTENT_ATTRIBUTE_UNSPECIFIED_NAME);
341
			JpaValidationMessages.PERSISTENT_ATTRIBUTE_UNSPECIFIED_NAME);
Lines 395-401 Link Here
395
			JpaValidationMessages.ELEMENT_COLLECTION_MAP_KEY_CLASS_NOT_DEFINED);
395
			JpaValidationMessages.ELEMENT_COLLECTION_MAP_KEY_CLASS_NOT_DEFINED);
396
396
397
		parent = addSubExpandableSection(parent, JptUiValidationPreferenceMessages.IMPLIED_ATTRIBUTE_LEVEL_CATEGORY);
397
		parent = addSubExpandableSection(parent, JptUiValidationPreferenceMessages.IMPLIED_ATTRIBUTE_LEVEL_CATEGORY);
398
		
398
399
		addLabeledCombo(
399
		addLabeledCombo(
400
			parent, JptUiValidationPreferenceMessages.VIRTUAL_ATTRIBUTE_TARGET_ENTITY_IS_NOT_AN_ENTITY,
400
			parent, JptUiValidationPreferenceMessages.VIRTUAL_ATTRIBUTE_TARGET_ENTITY_IS_NOT_AN_ENTITY,
401
			JpaValidationMessages.VIRTUAL_ATTRIBUTE_TARGET_ENTITY_IS_NOT_AN_ENTITY);
401
			JpaValidationMessages.VIRTUAL_ATTRIBUTE_TARGET_ENTITY_IS_NOT_AN_ENTITY);
Lines 410-416 Link Here
410
			JpaValidationMessages.VIRTUAL_ATTRIBUTE_ELEMENT_COLLECTION_TARGET_CLASS_MUST_BE_EMBEDDABLE_OR_BASIC_TYPE);
410
			JpaValidationMessages.VIRTUAL_ATTRIBUTE_ELEMENT_COLLECTION_TARGET_CLASS_MUST_BE_EMBEDDABLE_OR_BASIC_TYPE);
411
		addLabeledCombo(
411
		addLabeledCombo(
412
			parent, JptUiValidationPreferenceMessages.VIRTUAL_ATTRIBUTE_ELEMENT_COLLECTION_MAP_KEY_CLASS_NOT_DEFINED,
412
			parent, JptUiValidationPreferenceMessages.VIRTUAL_ATTRIBUTE_ELEMENT_COLLECTION_MAP_KEY_CLASS_NOT_DEFINED,
413
			JpaValidationMessages.VIRTUAL_ATTRIBUTE_ELEMENT_COLLECTION_MAP_KEY_CLASS_NOT_DEFINED);	
413
			JpaValidationMessages.VIRTUAL_ATTRIBUTE_ELEMENT_COLLECTION_MAP_KEY_CLASS_NOT_DEFINED);
414
	}
414
	}
415
415
416
	private void addDatabaseCategory(Composite parent) {
416
	private void addDatabaseCategory(Composite parent) {
Lines 423-431 Link Here
423
	}
423
	}
424
424
425
	private void addTableCategory(Composite parent) {
425
	private void addTableCategory(Composite parent) {
426
		
426
427
		parent = addExpandableSection(parent, JptUiValidationPreferenceMessages.TABLE_CATEGORY);
427
		parent = addExpandableSection(parent, JptUiValidationPreferenceMessages.TABLE_CATEGORY);
428
		
428
429
		addLabeledCombo(parent, JptUiValidationPreferenceMessages.TABLE_UNRESOLVED_CATALOG,                                            					JpaValidationMessages.TABLE_UNRESOLVED_CATALOG);
429
		addLabeledCombo(parent, JptUiValidationPreferenceMessages.TABLE_UNRESOLVED_CATALOG,                                            					JpaValidationMessages.TABLE_UNRESOLVED_CATALOG);
430
		addLabeledCombo(parent, JptUiValidationPreferenceMessages.TABLE_UNRESOLVED_SCHEMA,                                             					JpaValidationMessages.TABLE_UNRESOLVED_SCHEMA);
430
		addLabeledCombo(parent, JptUiValidationPreferenceMessages.TABLE_UNRESOLVED_SCHEMA,                                             					JpaValidationMessages.TABLE_UNRESOLVED_SCHEMA);
431
		addLabeledCombo(parent, JptUiValidationPreferenceMessages.TABLE_UNRESOLVED_NAME,                                               					JpaValidationMessages.TABLE_UNRESOLVED_NAME);
431
		addLabeledCombo(parent, JptUiValidationPreferenceMessages.TABLE_UNRESOLVED_NAME,                                               					JpaValidationMessages.TABLE_UNRESOLVED_NAME);
Lines 452-461 Link Here
452
		addLabeledCombo(parent, JptUiValidationPreferenceMessages.VIRTUAL_ATTRIBUTE_COLLECTION_TABLE_UNRESOLVED_SCHEMA,                                 JpaValidationMessages.VIRTUAL_ATTRIBUTE_COLLECTION_TABLE_UNRESOLVED_SCHEMA);
452
		addLabeledCombo(parent, JptUiValidationPreferenceMessages.VIRTUAL_ATTRIBUTE_COLLECTION_TABLE_UNRESOLVED_SCHEMA,                                 JpaValidationMessages.VIRTUAL_ATTRIBUTE_COLLECTION_TABLE_UNRESOLVED_SCHEMA);
453
		addLabeledCombo(parent, JptUiValidationPreferenceMessages.VIRTUAL_ATTRIBUTE_COLLECTION_TABLE_UNRESOLVED_NAME,                                   JpaValidationMessages.VIRTUAL_ATTRIBUTE_COLLECTION_TABLE_UNRESOLVED_NAME);
453
		addLabeledCombo(parent, JptUiValidationPreferenceMessages.VIRTUAL_ATTRIBUTE_COLLECTION_TABLE_UNRESOLVED_NAME,                                   JpaValidationMessages.VIRTUAL_ATTRIBUTE_COLLECTION_TABLE_UNRESOLVED_NAME);
454
	}
454
	}
455
	
455
456
	private void addColumnCategory(Composite parent) {	
456
	private void addColumnCategory(Composite parent) {
457
		parent = addExpandableSection(parent, JptUiValidationPreferenceMessages.COLUMN_CATEGORY);
457
		parent = addExpandableSection(parent, JptUiValidationPreferenceMessages.COLUMN_CATEGORY);
458
		
458
459
		addLabeledCombo(parent, JptUiValidationPreferenceMessages.COLUMN_TABLE_NOT_VALID,                                      							JpaValidationMessages.COLUMN_TABLE_NOT_VALID);
459
		addLabeledCombo(parent, JptUiValidationPreferenceMessages.COLUMN_TABLE_NOT_VALID,                                      							JpaValidationMessages.COLUMN_TABLE_NOT_VALID);
460
		addLabeledCombo(parent, JptUiValidationPreferenceMessages.COLUMN_UNRESOLVED_TABLE,                                             					JpaValidationMessages.COLUMN_UNRESOLVED_TABLE);
460
		addLabeledCombo(parent, JptUiValidationPreferenceMessages.COLUMN_UNRESOLVED_TABLE,                                             					JpaValidationMessages.COLUMN_UNRESOLVED_TABLE);
461
		addLabeledCombo(parent, JptUiValidationPreferenceMessages.COLUMN_UNRESOLVED_NAME,                                              					JpaValidationMessages.COLUMN_UNRESOLVED_NAME);
461
		addLabeledCombo(parent, JptUiValidationPreferenceMessages.COLUMN_UNRESOLVED_NAME,                                              					JpaValidationMessages.COLUMN_UNRESOLVED_NAME);
Lines 503-509 Link Here
503
		addLabeledCombo(parent, JptUiValidationPreferenceMessages.VIRTUAL_ATTRIBUTE_MAP_KEY_COLUMN_TABLE_NOT_VALID, 													JpaValidationMessages.VIRTUAL_ATTRIBUTE_MAP_KEY_COLUMN_TABLE_NOT_VALID);
503
		addLabeledCombo(parent, JptUiValidationPreferenceMessages.VIRTUAL_ATTRIBUTE_MAP_KEY_COLUMN_TABLE_NOT_VALID, 													JpaValidationMessages.VIRTUAL_ATTRIBUTE_MAP_KEY_COLUMN_TABLE_NOT_VALID);
504
	}
504
	}
505
505
506
	private void addOverridesCategory(Composite parent) {	
506
	private void addOverridesCategory(Composite parent) {
507
507
508
		parent = addExpandableSection(parent, JptUiValidationPreferenceMessages.OVERRIDES_CATEGORY);
508
		parent = addExpandableSection(parent, JptUiValidationPreferenceMessages.OVERRIDES_CATEGORY);
509
509
Lines 529-535 Link Here
529
		addLabeledCombo(parent, JptUiValidationPreferenceMessages.VIRTUAL_ASSOCIATION_OVERRIDE_INVERSE_JOIN_COLUMN_NAME_MUST_BE_SPECIFIED_MULTIPLE_INVERSE_JOIN_COLUMNS, 				JpaValidationMessages.VIRTUAL_ASSOCIATION_OVERRIDE_INVERSE_JOIN_COLUMN_NAME_MUST_BE_SPECIFIED_MULTIPLE_INVERSE_JOIN_COLUMNS);
529
		addLabeledCombo(parent, JptUiValidationPreferenceMessages.VIRTUAL_ASSOCIATION_OVERRIDE_INVERSE_JOIN_COLUMN_NAME_MUST_BE_SPECIFIED_MULTIPLE_INVERSE_JOIN_COLUMNS, 				JpaValidationMessages.VIRTUAL_ASSOCIATION_OVERRIDE_INVERSE_JOIN_COLUMN_NAME_MUST_BE_SPECIFIED_MULTIPLE_INVERSE_JOIN_COLUMNS);
530
		addLabeledCombo(parent, JptUiValidationPreferenceMessages.VIRTUAL_ASSOCIATION_OVERRIDE_INVERSE_JOIN_COLUMN_REFERENCED_COLUMN_NAME_MUST_BE_SPECIFIED_MULTIPLE_INVERSE_JOIN_COLUMNS, JpaValidationMessages.VIRTUAL_ASSOCIATION_OVERRIDE_INVERSE_JOIN_COLUMN_REFERENCED_COLUMN_NAME_MUST_BE_SPECIFIED_MULTIPLE_INVERSE_JOIN_COLUMNS);
530
		addLabeledCombo(parent, JptUiValidationPreferenceMessages.VIRTUAL_ASSOCIATION_OVERRIDE_INVERSE_JOIN_COLUMN_REFERENCED_COLUMN_NAME_MUST_BE_SPECIFIED_MULTIPLE_INVERSE_JOIN_COLUMNS, JpaValidationMessages.VIRTUAL_ASSOCIATION_OVERRIDE_INVERSE_JOIN_COLUMN_REFERENCED_COLUMN_NAME_MUST_BE_SPECIFIED_MULTIPLE_INVERSE_JOIN_COLUMNS);
531
531
532
		
532
533
		parent = addSubExpandableSection(parent, JptUiValidationPreferenceMessages.IMPLIED_ATTRIBUTE_LEVEL_CATEGORY);
533
		parent = addSubExpandableSection(parent, JptUiValidationPreferenceMessages.IMPLIED_ATTRIBUTE_LEVEL_CATEGORY);
534
534
535
		addLabeledCombo(parent, JptUiValidationPreferenceMessages.VIRTUAL_ATTRIBUTE_ATTRIBUTE_OVERRIDE_INVALID_NAME,                  									JpaValidationMessages.VIRTUAL_ATTRIBUTE_ATTRIBUTE_OVERRIDE_INVALID_NAME);
535
		addLabeledCombo(parent, JptUiValidationPreferenceMessages.VIRTUAL_ATTRIBUTE_ATTRIBUTE_OVERRIDE_INVALID_NAME,                  									JpaValidationMessages.VIRTUAL_ATTRIBUTE_ATTRIBUTE_OVERRIDE_INVALID_NAME);
Lines 591-602 Link Here
591
		addLabeledCombo(parent, JptUiValidationPreferenceMessages.ID_MAPPING_UNRESOLVED_GENERATOR_NAME, JpaValidationMessages.ID_MAPPING_UNRESOLVED_GENERATOR_NAME);
591
		addLabeledCombo(parent, JptUiValidationPreferenceMessages.ID_MAPPING_UNRESOLVED_GENERATOR_NAME, JpaValidationMessages.ID_MAPPING_UNRESOLVED_GENERATOR_NAME);
592
		addLabeledCombo(parent, JptUiValidationPreferenceMessages.GENERATED_VALUE_UNRESOLVED_GENERATOR, JpaValidationMessages.GENERATED_VALUE_UNRESOLVED_GENERATOR);
592
		addLabeledCombo(parent, JptUiValidationPreferenceMessages.GENERATED_VALUE_UNRESOLVED_GENERATOR, JpaValidationMessages.GENERATED_VALUE_UNRESOLVED_GENERATOR);
593
		addLabeledCombo(parent, JptUiValidationPreferenceMessages.QUERY_DUPLICATE_NAME,                 JpaValidationMessages.QUERY_DUPLICATE_NAME);
593
		addLabeledCombo(parent, JptUiValidationPreferenceMessages.QUERY_DUPLICATE_NAME,                 JpaValidationMessages.QUERY_DUPLICATE_NAME);
594
		addLabeledCombo(parent, JptUiValidationPreferenceMessages.JPQL_QUERY_VALIDATION,                JpaValidationMessages.JPQL_QUERY_VALIDATION);
594
	}
595
	}
595
	
596
596
	private Composite addExpandableSection(Composite parent, String text) {
597
	private Composite addExpandableSection(Composite parent, String text) {
597
		return addExpandableSection(parent, text, new GridData(GridData.FILL, GridData.FILL, true, false));
598
		return addExpandableSection(parent, text, new GridData(GridData.FILL, GridData.FILL, true, false));
598
	}
599
	}
599
	
600
600
	private Composite addSubExpandableSection(Composite parent, String text) {
601
	private Composite addSubExpandableSection(Composite parent, String text) {
601
		return addExpandableSection(parent, text, new GridData(GridData.FILL, GridData.FILL, true, false, 2, 1));
602
		return addExpandableSection(parent, text, new GridData(GridData.FILL, GridData.FILL, true, false, 2, 1));
602
	}
603
	}
Lines 714-720 Link Here
714
		String preference = this.defaultSeverities.get(preferenceKey);
715
		String preference = this.defaultSeverities.get(preferenceKey);
715
		return preference == null ? JpaValidationPreferences.ERROR : preference;
716
		return preference == null ? JpaValidationPreferences.ERROR : preference;
716
	}
717
	}
717
	
718
718
	protected int convertPreferenceValueToComboIndex(String preferenceValue) {
719
	protected int convertPreferenceValueToComboIndex(String preferenceValue) {
719
		if (JpaValidationPreferences.ERROR.equals(preferenceValue)) {
720
		if (JpaValidationPreferences.ERROR.equals(preferenceValue)) {
720
			return ERROR_INDEX;
721
			return ERROR_INDEX;
Lines 778-784 Link Here
778
			revertToDefault();
779
			revertToDefault();
779
		}
780
		}
780
	}
781
	}
781
	
782
782
	@Override
783
	@Override
783
	protected void enableProjectSpecificSettings(boolean useProjectSpecificSettings) {
784
	protected void enableProjectSpecificSettings(boolean useProjectSpecificSettings) {
784
		super.enableProjectSpecificSettings(useProjectSpecificSettings);
785
		super.enableProjectSpecificSettings(useProjectSpecificSettings);
Lines 787-795 Link Here
787
			//      "otherwise the 'enable project specific settings' checkbox is being pressed")
788
			//      "otherwise the 'enable project specific settings' checkbox is being pressed")
788
			return;
789
			return;
789
		}
790
		}
790
		
791
791
		this.hasProjectSpecificPreferences = Boolean.valueOf(useProjectSpecificSettings);
792
		this.hasProjectSpecificPreferences = Boolean.valueOf(useProjectSpecificSettings);
792
		
793
793
		//set all specified workspace preferences in the project preferences
794
		//set all specified workspace preferences in the project preferences
794
		if (useProjectSpecificSettings){
795
		if (useProjectSpecificSettings){
795
			this.overrideWorkspacePreferences();
796
			this.overrideWorkspacePreferences();
Lines 812-818 Link Here
812
				preference = getDefaultPreferenceValue(preferenceKey);
813
				preference = getDefaultPreferenceValue(preferenceKey);
813
			}
814
			}
814
			combo.select(convertPreferenceValueToComboIndex(preference));
815
			combo.select(convertPreferenceValueToComboIndex(preference));
815
			//UI will show the defaults from the workspace, but set all preferences 
816
			//UI will show the defaults from the workspace, but set all preferences
816
			//to null so they will be deleted from project preferences
817
			//to null so they will be deleted from project preferences
817
			this.severityLevels.put(preferenceKey, null);
818
			this.severityLevels.put(preferenceKey, null);
818
		}
819
		}
Lines 833-839 Link Here
833
			}
834
			}
834
		}
835
		}
835
	}
836
	}
836
	
837
837
	// ********** OK/Revert/Apply behavior **********
838
	// ********** OK/Revert/Apply behavior **********
838
839
839
	@Override
840
	@Override
Lines 858-864 Link Here
858
		}
859
		}
859
		catch (InterruptedException ex) {
860
		catch (InterruptedException ex) {
860
			return false;
861
			return false;
861
		} 
862
		}
862
		catch (InvocationTargetException ex) {
863
		catch (InvocationTargetException ex) {
863
			throw new RuntimeException(ex.getTargetException());
864
			throw new RuntimeException(ex.getTargetException());
864
		}
865
		}
(-)src/org/eclipse/jpt/jpa/ui/internal/prefs/JpaUiPreferenceInitializer.java (+42 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2009 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
6
 *
7
 * Contributors:
8
 *     Oracle - initial API and implementation
9
 ******************************************************************************/
10
package org.eclipse.jpt.jpa.ui.internal.prefs;
11
12
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
13
import org.eclipse.jface.preference.IPreferenceStore;
14
import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
15
16
/**
17
 * The initializer of the JPA UI preferences, which sets the default values.
18
 *
19
 * @version 3.0
20
 * @since 3.0
21
 * @author Pascal Filion
22
 */
23
public class JpaUiPreferenceInitializer extends AbstractPreferenceInitializer {
24
25
	/**
26
	 * Creates a new <code>JpaUiPreferenceInitializer</code>.
27
	 */
28
	public JpaUiPreferenceInitializer() {
29
		super();
30
	}
31
32
	/**
33
	 * {@inheritDoc}
34
	 */
35
	@Override
36
	public void initializeDefaultPreferences() {
37
38
		IPreferenceStore preferences = JptJpaUiPlugin.instance().getPreferenceStore();
39
		preferences.setDefault(JptJpaUiPlugin.JPQL_IDENTIFIER_CASE_PREF_KEY, JptJpaUiPlugin.JPQL_IDENTIFIER_LOWERCASE_PREF_VALUE);
40
		preferences.setDefault(JptJpaUiPlugin.JPQL_IDENTIFIER_MATCH_FIRST_CHARACTER_CASE_PREF_KEY, true);
41
	}
42
}

Return to bug 337930