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

Collapse All | Expand All

(-)src/org/eclipse/jpt/jpa/core/JpaXmlStructureNode.java (+33 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2012 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;
11
12
13
/**
14
 * Implement this interface for XML objects that appear in the Structure view
15
 * 
16
 * Provisional API: This interface is part of an interim API that is still
17
 * under development and expected to change significantly before reaching
18
 * stability. It is available at this early stage to solicit feedback from
19
 * pioneering adopters on the understanding that any code that uses this API
20
 * will almost certainly be broken (repeatedly) as the API evolves.
21
 * 
22
 * @version 3.2
23
 * @since 3.2
24
 */
25
26
public interface JpaXmlStructureNode extends JpaStructureNode {
27
	
28
	/**
29
	 * Return the content assist proposals for the specified position
30
	 * in the XML file.
31
	 */
32
	Iterable<String> getXmlCompletionProposals(int pos);
33
}
(-)src/org/eclipse/jpt/jpa/core/context/MappingFileRoot.java (-3 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2008, 2012 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-15 Link Here
9
 ******************************************************************************/
9
 ******************************************************************************/
10
package org.eclipse.jpt.jpa.core.context;
10
package org.eclipse.jpt.jpa.core.context;
11
11
12
import org.eclipse.jpt.jpa.core.JpaStructureNode;
12
import org.eclipse.jpt.jpa.core.JpaXmlStructureNode;
13
import org.eclipse.jpt.jpa.core.context.persistence.PersistentTypeContainer;
13
import org.eclipse.jpt.jpa.core.context.persistence.PersistentTypeContainer;
14
14
15
/**
15
/**
Lines 25-31 Link Here
25
 * @since 2.1
25
 * @since 2.1
26
 */
26
 */
27
public interface MappingFileRoot
27
public interface MappingFileRoot
28
	extends XmlContextNode, JpaStructureNode, PersistentTypeContainer
28
	extends XmlContextNode, JpaXmlStructureNode, PersistentTypeContainer
29
{
29
{
30
	/**
30
	/**
31
	 * covariant override
31
	 * covariant override
(-)src/org/eclipse/jpt/jpa/core/context/XmlContextNode.java (-1 / +7 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2010 Oracle. All rights reserved.
2
 * Copyright (c) 2008, 2012 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 31-36 Link Here
31
	extends JpaContextNode
31
	extends JpaContextNode
32
{
32
{
33
// TODO bjv rename to XmlJpaContextNode
33
// TODO bjv rename to XmlJpaContextNode
34
35
	/**
36
	 * Return the content assist proposals for the specified position
37
	 * in the XML file.
38
	 */
39
	Iterable<String> getXmlCompletionProposals(int pos);
34
	/**
40
	/**
35
	 * Add to the list of current validation messages
41
	 * Add to the list of current validation messages
36
	 */
42
	 */
(-)src/org/eclipse/jpt/jpa/core/context/persistence/Persistence.java (-2 / +2 lines)
Lines 10-16 Link Here
10
package org.eclipse.jpt.jpa.core.context.persistence;
10
package org.eclipse.jpt.jpa.core.context.persistence;
11
11
12
import org.eclipse.jpt.common.utility.internal.iterables.ListIterable;
12
import org.eclipse.jpt.common.utility.internal.iterables.ListIterable;
13
import org.eclipse.jpt.jpa.core.JpaStructureNode;
13
import org.eclipse.jpt.jpa.core.JpaXmlStructureNode;
14
import org.eclipse.jpt.jpa.core.context.XmlContextNode;
14
import org.eclipse.jpt.jpa.core.context.XmlContextNode;
15
import org.eclipse.jpt.jpa.core.resource.persistence.XmlPersistence;
15
import org.eclipse.jpt.jpa.core.resource.persistence.XmlPersistence;
16
16
Lines 29-35 Link Here
29
 * @since 2.0
29
 * @since 2.0
30
 */
30
 */
31
public interface Persistence
31
public interface Persistence
32
	extends XmlContextNode, JpaStructureNode
32
	extends XmlContextNode, JpaXmlStructureNode
33
{
33
{
34
	/**
34
	/**
35
	 * Return the resource model object associated with this context model object
35
	 * Return the resource model object associated with this context model object
(-)src/org/eclipse/jpt/jpa/core/context/persistence/PersistenceUnit.java (-2 / +17 lines)
Lines 21-26 Link Here
21
import org.eclipse.jpt.jpa.core.context.Embeddable;
21
import org.eclipse.jpt.jpa.core.context.Embeddable;
22
import org.eclipse.jpt.jpa.core.context.Entity;
22
import org.eclipse.jpt.jpa.core.context.Entity;
23
import org.eclipse.jpt.jpa.core.context.Generator;
23
import org.eclipse.jpt.jpa.core.context.Generator;
24
import org.eclipse.jpt.jpa.core.context.PersistentType;
24
import org.eclipse.jpt.jpa.core.context.Query;
25
import org.eclipse.jpt.jpa.core.context.Query;
25
import org.eclipse.jpt.jpa.core.context.XmlContextNode;
26
import org.eclipse.jpt.jpa.core.context.XmlContextNode;
26
import org.eclipse.jpt.jpa.core.jpql.JpaJpqlQueryHelper;
27
import org.eclipse.jpt.jpa.core.jpql.JpaJpqlQueryHelper;
Lines 699-704 Link Here
699
	boolean specifiesPersistentType(String typeName);
700
	boolean specifiesPersistentType(String typeName);
700
701
701
	/**
702
	/**
703
	 * Return the persistence unit's Java persistent types, as specified by
704
	 * the class refs (both specified and implied) and jar files.
705
	 * There can be duplicate types, and any of them may be overridden by a
706
	 * mapping file persistence type.
707
	 * @see #getMappingFilePersistentTypes()
708
	 */
709
	Iterable<PersistentType> getJavaPersistentTypes();
710
711
	/**
702
	 * Return the persistence unit's entities.
712
	 * Return the persistence unit's entities.
703
	 */
713
	 */
704
	Iterable<Entity> getEntities();
714
	Iterable<Entity> getEntities();
Lines 732-739 Link Here
732
	 * types in the project currently annotated.
742
	 * types in the project currently annotated.
733
	 */
743
	 */
734
	void synchronizeClasses(IProgressMonitor monitor);
744
	void synchronizeClasses(IProgressMonitor monitor);
735
745
	
736
746
	/**
747
	 * Return the names of all the packages valid cross the persistence unit
748
	 * including the ones from jar files
749
	 */
750
	Iterable<String> getPackageNames();
751
	
737
	// ********** validation **********
752
	// ********** validation **********
738
753
739
	/**
754
	/**
(-)src/org/eclipse/jpt/jpa/core/internal/context/AbstractXmlContextNode.java (-1 / +24 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2007, 2012 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 62-65 Link Here
62
	protected TextRange getValidationTextRange(TextRange textRange) {
62
	protected TextRange getValidationTextRange(TextRange textRange) {
63
		return (textRange != null) ? textRange : this.getValidationTextRange();
63
		return (textRange != null) ? textRange : this.getValidationTextRange();
64
	}
64
	}
65
	
66
	// *********** completion proposals ***********
67
	
68
	public Iterable<String> getXmlCompletionProposals(int pos) {
69
		if (this.connectionProfileIsActive()) {
70
			Iterable<String> result = this.getConnectedXmlCompletionProposals(pos);
71
			if (result != null) {
72
				return result;
73
			}
74
		}
75
		return null;
76
	}
77
	
78
	/**
79
	 * This method is called if the database is connected, allowing us to
80
	 * get candidates from the various database tables etc.
81
	 * This method should <em>not</em> be cascaded to "child" objects; it should
82
	 * only return candidates for the current object. The cascading is
83
	 * handled by {@link #getXmlCompletionProposals(int)}.
84
	 */
85
	protected Iterable<String> getConnectedXmlCompletionProposals(int pos) {
86
		return null;
87
	}
65
}
88
}
(-)src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaMultiRelationshipMapping.java (-1 / +2 lines)
Lines 1264-1270 Link Here
1264
		}
1264
		}
1265
1265
1266
		public Table getReferencedColumnDbTable() {
1266
		public Table getReferencedColumnDbTable() {
1267
			return AbstractJavaMultiRelationshipMapping.this.getResolvedMapKeyEntity().getPrimaryDbTable();
1267
			Entity entity = AbstractJavaMultiRelationshipMapping.this.getResolvedMapKeyEntity();
1268
			return entity != null ? entity.getPrimaryDbTable() : null;
1268
		}
1269
		}
1269
1270
1270
		public int getJoinColumnsSize() {
1271
		public int getJoinColumnsSize() {
(-)src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractEntityMappings.java (+89 lines)
Lines 56-61 Link Here
56
import org.eclipse.jpt.jpa.core.resource.orm.XmlTableGenerator;
56
import org.eclipse.jpt.jpa.core.resource.orm.XmlTableGenerator;
57
import org.eclipse.jpt.jpa.core.resource.orm.XmlTypeMapping;
57
import org.eclipse.jpt.jpa.core.resource.orm.XmlTypeMapping;
58
import org.eclipse.jpt.jpa.db.Catalog;
58
import org.eclipse.jpt.jpa.db.Catalog;
59
import org.eclipse.jpt.jpa.db.Database;
59
import org.eclipse.jpt.jpa.db.Schema;
60
import org.eclipse.jpt.jpa.db.Schema;
60
import org.eclipse.jpt.jpa.db.SchemaContainer;
61
import org.eclipse.jpt.jpa.db.SchemaContainer;
61
import org.eclipse.text.edits.DeleteEdit;
62
import org.eclipse.text.edits.DeleteEdit;
Lines 1071-1074 Link Here
1071
				new SingleElementIterable<ReplaceEdit>(this.xmlEntityMappings.createRenamePackageEdit(newName)) :
1072
				new SingleElementIterable<ReplaceEdit>(this.xmlEntityMappings.createRenamePackageEdit(newName)) :
1072
				EmptyIterable.<ReplaceEdit>instance();
1073
				EmptyIterable.<ReplaceEdit>instance();
1073
	}
1074
	}
1075
	
1076
	// ************ completion proposals**************
1077
	
1078
	@Override
1079
	public Iterable<String> getXmlCompletionProposals(int pos) {
1080
		Iterable<String> result = super.getXmlCompletionProposals(pos);
1081
		if (result != null) {
1082
			return result;
1083
		}
1084
		result = this.queryContainer.getXmlCompletionProposals(pos);
1085
		if (result != null) {
1086
			return result;
1087
		}
1088
		for (OrmTableGenerator tableGenerator : this.getTableGenerators()) {
1089
			result = tableGenerator.getXmlCompletionProposals(pos);
1090
			if (result != null) {
1091
				return result;
1092
			}
1093
		}
1094
		for (OrmSequenceGenerator seqGenerator : this.getSequenceGenerators()) {
1095
			result = seqGenerator.getXmlCompletionProposals(pos);
1096
			if (result != null) {
1097
				return result;
1098
			}
1099
		}
1100
		result = this.persistenceUnitMetadata.getXmlCompletionProposals(pos);
1101
		if (result != null) {
1102
			return result;
1103
		}
1104
		if (this.packageTouches(pos)) {
1105
			return this.getCandidatePackages();
1106
		}
1107
		for (OrmPersistentType persistentType : this.getPersistentTypes()) {
1108
			result = persistentType.getXmlCompletionProposals(pos);
1109
			if (result != null) {
1110
				return result;
1111
			}
1112
		}
1113
		return null;
1114
	}
1115
1116
	@Override
1117
	protected Iterable<String> getConnectedXmlCompletionProposals(int pos) {
1118
		Iterable<String> result = super.getConnectedXmlCompletionProposals(pos);
1119
		if (result != null) {
1120
			return result;
1121
		}
1122
		if (this.schemaTouches(pos)) {
1123
			return this.getCandidateSchemata();
1124
		}
1125
		if (this.catalogTouches(pos)) {
1126
			return this.getCandidateCatalogs();
1127
		}
1128
		return null;
1129
	}
1130
	
1131
	// ********** content assist: schema
1132
1133
	protected boolean schemaTouches(int pos) {
1134
		return this.getXmlEntityMappings().schemaTouches(pos);
1135
	}
1136
1137
	protected Iterable<String> getCandidateSchemata() {
1138
		SchemaContainer schemaContainer = this.getDbSchemaContainer();
1139
		return (schemaContainer != null) ? schemaContainer.getSortedSchemaIdentifiers() : EmptyIterable.<String> instance();
1140
	}
1141
1142
	// ********** content assist: catalog
1143
1144
	protected boolean catalogTouches(int pos) {
1145
		return this.getXmlEntityMappings().catalogTouches(pos);
1146
	}
1147
1148
	protected Iterable<String> getCandidateCatalogs() {
1149
		Database db = this.getDatabase();
1150
		return (db != null) ? db.getSortedCatalogIdentifiers() : EmptyIterable.<String> instance();
1151
	}
1152
	
1153
	// ********** content assist: package
1154
	
1155
	private boolean packageTouches(int pos) {
1156
		return this.getXmlEntityMappings().packageTouches(pos);
1157
	}
1158
	
1159
	private Iterable<String> getCandidatePackages() {
1160
		return this.getPersistenceUnit().getPackageNames();
1161
	}
1162
1074
}
1163
}
(-)src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmAttributeMapping.java (+32 lines)
Lines 14-19 Link Here
14
import org.eclipse.jdt.core.IPackageFragment;
14
import org.eclipse.jdt.core.IPackageFragment;
15
import org.eclipse.jdt.core.IType;
15
import org.eclipse.jdt.core.IType;
16
import org.eclipse.jpt.common.core.utility.TextRange;
16
import org.eclipse.jpt.common.core.utility.TextRange;
17
import org.eclipse.jpt.common.utility.internal.CollectionTools;
17
import org.eclipse.jpt.common.utility.internal.StringTools;
18
import org.eclipse.jpt.common.utility.internal.StringTools;
18
import org.eclipse.jpt.common.utility.internal.Tools;
19
import org.eclipse.jpt.common.utility.internal.Tools;
19
import org.eclipse.jpt.common.utility.internal.Transformer;
20
import org.eclipse.jpt.common.utility.internal.Transformer;
Lines 27-32 Link Here
27
import org.eclipse.jpt.jpa.core.context.Relationship;
28
import org.eclipse.jpt.jpa.core.context.Relationship;
28
import org.eclipse.jpt.jpa.core.context.RelationshipMapping;
29
import org.eclipse.jpt.jpa.core.context.RelationshipMapping;
29
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
30
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
31
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
30
import org.eclipse.jpt.jpa.core.context.orm.EntityMappings;
32
import org.eclipse.jpt.jpa.core.context.orm.EntityMappings;
31
import org.eclipse.jpt.jpa.core.context.orm.OrmAttributeMapping;
33
import org.eclipse.jpt.jpa.core.context.orm.OrmAttributeMapping;
32
import org.eclipse.jpt.jpa.core.context.orm.OrmBaseEmbeddedMapping;
34
import org.eclipse.jpt.jpa.core.context.orm.OrmBaseEmbeddedMapping;
Lines 506-509 Link Here
506
			);
508
			);
507
		}
509
		}
508
	}
510
	}
511
	
512
	// ********** completion proposals **********
513
514
	@Override
515
	public Iterable<String> getXmlCompletionProposals(int pos) {
516
		Iterable<String> result = super.getXmlCompletionProposals(pos);
517
		if (result != null) {
518
			return result;
519
		}
520
		if (this.attributeNameTouches(pos)) {
521
			return this.getCandidateMappingNames();
522
		}
523
		return null;
524
	}
525
	
526
	/**
527
	 * @return all the attribute of corresponding Java persistent type
528
	 */
529
	// Attributes of the corresponding XML persistent type include these
530
	// that are already defined in XML so using these attributes as candidates
531
	// could lead to multiple attribute mappings with the same name;
532
	// thus using the attribute of the corresponding Java persistent type instead
533
	private Iterable<String> getCandidateMappingNames() {
534
		JavaPersistentType jpt = this.getTypeMapping().getPersistentType().getJavaPersistentType();
535
		return jpt == null ? EmptyIterable.<String>instance() : CollectionTools.collection(jpt.getAttributeNames());
536
	}
537
538
	private boolean attributeNameTouches(int pos) {
539
		return this.getXmlAttributeMapping().nameTouches(pos);
540
	}
509
}
541
}
(-)src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmBaseColumn.java (-1 / +20 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2007, 2012 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 299-302 Link Here
299
	protected NamedColumnTextRangeResolver buildTextRangeResolver() {
299
	protected NamedColumnTextRangeResolver buildTextRangeResolver() {
300
		return new OrmTableColumnTextRangeResolver(this);
300
		return new OrmTableColumnTextRangeResolver(this);
301
	}
301
	}
302
	
303
	// ********** completion proposals **********
304
305
	@Override
306
	public Iterable<String> getXmlCompletionProposals(int pos) {
307
		Iterable<String> result = super.getXmlCompletionProposals(pos);
308
		if (result != null) {
309
			return result;
310
		}
311
		if (this.tableTouches(pos)) {
312
			return this.getCandidateTableNames();
313
		}
314
		return null;
315
	}
316
317
	protected boolean tableTouches(int pos) {
318
		X xmlColumn = this.getXmlColumn();
319
		return (xmlColumn != null) && (xmlColumn.tableTouches(pos));
320
	}
302
}
321
}
(-)src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmBaseEmbeddedMapping.java (-1 / +15 lines)
Lines 32-41 Link Here
32
import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentAttribute;
32
import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentAttribute;
33
import org.eclipse.jpt.jpa.core.context.orm.OrmTypeMapping;
33
import org.eclipse.jpt.jpa.core.context.orm.OrmTypeMapping;
34
import org.eclipse.jpt.jpa.core.internal.context.AttributeMappingTools;
34
import org.eclipse.jpt.jpa.core.internal.context.AttributeMappingTools;
35
import org.eclipse.jpt.jpa.core.internal.context.TableColumnTextRangeResolver;
36
import org.eclipse.jpt.jpa.core.internal.context.JptValidator;
35
import org.eclipse.jpt.jpa.core.internal.context.JptValidator;
37
import org.eclipse.jpt.jpa.core.internal.context.MappingTools;
36
import org.eclipse.jpt.jpa.core.internal.context.MappingTools;
38
import org.eclipse.jpt.jpa.core.internal.context.OverrideTextRangeResolver;
37
import org.eclipse.jpt.jpa.core.internal.context.OverrideTextRangeResolver;
38
import org.eclipse.jpt.jpa.core.internal.context.TableColumnTextRangeResolver;
39
import org.eclipse.jpt.jpa.core.internal.jpa1.context.AttributeOverrideColumnValidator;
39
import org.eclipse.jpt.jpa.core.internal.jpa1.context.AttributeOverrideColumnValidator;
40
import org.eclipse.jpt.jpa.core.internal.jpa1.context.AttributeOverrideValidator;
40
import org.eclipse.jpt.jpa.core.internal.jpa1.context.AttributeOverrideValidator;
41
import org.eclipse.jpt.jpa.core.internal.jpa1.context.EmbeddableOverrideDescriptionProvider;
41
import org.eclipse.jpt.jpa.core.internal.jpa1.context.EmbeddableOverrideDescriptionProvider;
Lines 230-235 Link Here
230
		this.attributeOverrideContainer.validate(messages, reporter);
230
		this.attributeOverrideContainer.validate(messages, reporter);
231
	}
231
	}
232
232
233
	// ********** completion proposals **********
234
235
	@Override
236
	public Iterable<String> getXmlCompletionProposals(int pos) {
237
		Iterable<String> result = super.getXmlCompletionProposals(pos);
238
		if (result != null) {
239
			return result;
240
		}
241
		result = this.attributeOverrideContainer.getXmlCompletionProposals(pos);
242
		if (result != null) {
243
			return result;
244
		}
245
		return null;
246
	}
233
247
234
	// ********** attribute override container owner *********
248
	// ********** attribute override container owner *********
235
249
(-)src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmBasicMapping.java (-2 / +21 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2006, 2012 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 26-34 Link Here
26
import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentAttribute;
26
import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentAttribute;
27
import org.eclipse.jpt.jpa.core.context.orm.OrmTemporalConverter;
27
import org.eclipse.jpt.jpa.core.context.orm.OrmTemporalConverter;
28
import org.eclipse.jpt.jpa.core.context.orm.OrmXmlContextNodeFactory;
28
import org.eclipse.jpt.jpa.core.context.orm.OrmXmlContextNodeFactory;
29
import org.eclipse.jpt.jpa.core.internal.context.TableColumnTextRangeResolver;
30
import org.eclipse.jpt.jpa.core.internal.context.JptValidator;
29
import org.eclipse.jpt.jpa.core.internal.context.JptValidator;
31
import org.eclipse.jpt.jpa.core.internal.context.NamedColumnTextRangeResolver;
30
import org.eclipse.jpt.jpa.core.internal.context.NamedColumnTextRangeResolver;
31
import org.eclipse.jpt.jpa.core.internal.context.TableColumnTextRangeResolver;
32
import org.eclipse.jpt.jpa.core.internal.jpa1.context.EntityTableDescriptionProvider;
32
import org.eclipse.jpt.jpa.core.internal.jpa1.context.EntityTableDescriptionProvider;
33
import org.eclipse.jpt.jpa.core.internal.jpa1.context.NamedColumnValidator;
33
import org.eclipse.jpt.jpa.core.internal.jpa1.context.NamedColumnValidator;
34
import org.eclipse.jpt.jpa.core.internal.jpa1.context.orm.NullOrmConverter;
34
import org.eclipse.jpt.jpa.core.internal.jpa1.context.orm.NullOrmConverter;
Lines 368-371 Link Here
368
	public JptValidator buildColumnValidator(ReadOnlyNamedColumn col, NamedColumnTextRangeResolver textRangeResolver) {
368
	public JptValidator buildColumnValidator(ReadOnlyNamedColumn col, NamedColumnTextRangeResolver textRangeResolver) {
369
		return new NamedColumnValidator(this.getPersistentAttribute(), (ReadOnlyBaseColumn) col, (TableColumnTextRangeResolver) textRangeResolver, new EntityTableDescriptionProvider());
369
		return new NamedColumnValidator(this.getPersistentAttribute(), (ReadOnlyBaseColumn) col, (TableColumnTextRangeResolver) textRangeResolver, new EntityTableDescriptionProvider());
370
	}
370
	}
371
	
372
	// ********** completion proposals **********
373
374
	@Override
375
	public Iterable<String> getXmlCompletionProposals(int pos) {
376
		Iterable<String> result = super.getXmlCompletionProposals(pos);
377
		if (result != null) {
378
			return result;
379
		}
380
		result = this.column.getXmlCompletionProposals(pos);
381
		if (result != null) {
382
			return result;
383
		}
384
		result = this.converter.getXmlCompletionProposals(pos);
385
		if (result != null) {
386
			return result;
387
		}
388
		return null;
389
	}
371
}
390
}
(-)src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmEntity.java (+42 lines)
Lines 1918-1923 Link Here
1918
		return this.getValidationTextRange(this.xmlTypeMapping.getInheritanceStrategyTextRange());
1918
		return this.getValidationTextRange(this.xmlTypeMapping.getInheritanceStrategyTextRange());
1919
	}
1919
	}
1920
1920
1921
	// ********** completion proposals **********
1922
1923
	@Override
1924
	public Iterable<String> getXmlCompletionProposals(int pos) {
1925
		Iterable<String> result = super.getXmlCompletionProposals(pos);
1926
		if (result != null) {
1927
			return result;
1928
		}
1929
		result = this.table.getXmlCompletionProposals(pos);
1930
		if (result != null) {
1931
			return result;
1932
		}
1933
		for (OrmSecondaryTable secondaryTable : this.getSpecifiedSecondaryTables()) {
1934
			result = secondaryTable.getXmlCompletionProposals(pos);
1935
			if (result != null) {
1936
				return result;
1937
			}
1938
		}
1939
		for (OrmPrimaryKeyJoinColumn pkJoinColumn : this.getSpecifiedPrimaryKeyJoinColumns()) {
1940
			result = pkJoinColumn.getXmlCompletionProposals(pos);
1941
			if (result != null) {
1942
				return result;
1943
			}
1944
		}
1945
		result = this.attributeOverrideContainer.getXmlCompletionProposals(pos);
1946
		if (result != null) {
1947
			return result;
1948
		}
1949
		result = this.associationOverrideContainer.getXmlCompletionProposals(pos);
1950
		if (result != null) {
1951
			return result;
1952
		}
1953
		result = this.discriminatorColumn.getXmlCompletionProposals(pos);
1954
		if (result != null) {
1955
			return result;
1956
		}
1957
		result = this.generatorContainer.getXmlCompletionProposals(pos);
1958
		if (result != null) {
1959
			return result;
1960
		}
1961
		return null;
1962
	}
1921
1963
1922
	// ********** OrmOverrideContainer.Owner implementation **********
1964
	// ********** OrmOverrideContainer.Owner implementation **********
1923
1965
(-)src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmGenerator.java (-1 / +45 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2007, 2012 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 13-18 Link Here
13
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;
14
import org.eclipse.jpt.common.utility.internal.StringTools;
15
import org.eclipse.jpt.common.utility.internal.Tools;
15
import org.eclipse.jpt.common.utility.internal.Tools;
16
import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable;
16
import org.eclipse.jpt.jpa.core.context.Generator;
17
import org.eclipse.jpt.jpa.core.context.Generator;
17
import org.eclipse.jpt.jpa.core.context.XmlContextNode;
18
import org.eclipse.jpt.jpa.core.context.XmlContextNode;
18
import org.eclipse.jpt.jpa.core.context.orm.OrmGenerator;
19
import org.eclipse.jpt.jpa.core.context.orm.OrmGenerator;
Lines 20-25 Link Here
20
import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages;
21
import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages;
21
import org.eclipse.jpt.jpa.core.resource.orm.XmlGenerator;
22
import org.eclipse.jpt.jpa.core.resource.orm.XmlGenerator;
22
import org.eclipse.jpt.jpa.db.Catalog;
23
import org.eclipse.jpt.jpa.db.Catalog;
24
import org.eclipse.jpt.jpa.db.Database;
23
import org.eclipse.jpt.jpa.db.Schema;
25
import org.eclipse.jpt.jpa.db.Schema;
24
import org.eclipse.jpt.jpa.db.SchemaContainer;
26
import org.eclipse.jpt.jpa.db.SchemaContainer;
25
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
27
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
Lines 192-197 Link Here
192
				Tools.valuesAreEqual(this.getSpecifiedInitialValue(), generator.getSpecifiedInitialValue());
194
				Tools.valuesAreEqual(this.getSpecifiedInitialValue(), generator.getSpecifiedInitialValue());
193
	}
195
	}
194
196
197
	// ************* completion proposals *************
198
	/**
199
	 * called if the database is connected:
200
	 * table, schema, catalog, pkColumnName, valueColumnName
201
	 */
202
	@Override
203
	protected Iterable<String> getConnectedXmlCompletionProposals(int pos) {
204
		Iterable<String> result = super.getConnectedXmlCompletionProposals(pos);
205
		if (result != null) {
206
			return result;
207
		}
208
		if (this.schemaTouches(pos)) {
209
			return this.getCandidateSchemata();
210
		}
211
		if (this.catalogTouches(pos)) {
212
			return this.getCandidateCatalogs();
213
		}
214
		return null;
215
	}
216
217
	// ********** content assist: schema
218
219
	protected boolean schemaTouches(int pos) {
220
		return this.xmlGenerator.schemaTouches(pos);
221
	}
222
223
	protected Iterable<String> getCandidateSchemata() {
224
		SchemaContainer schemaContainer = this.getDbSchemaContainer();
225
		return (schemaContainer != null) ? schemaContainer.getSortedSchemaIdentifiers() : EmptyIterable.<String> instance();
226
	}
227
228
	// ********** content assist: catalog
229
230
	protected boolean catalogTouches(int pos) {
231
		return this.xmlGenerator.catalogTouches(pos);
232
	}
233
234
	protected Iterable<String> getCandidateCatalogs() {
235
		Database db = this.getDatabase();
236
		return (db != null) ? db.getSortedCatalogIdentifiers() : EmptyIterable.<String> instance();
237
	}
238
195
	// ********** database stuff **********
239
	// ********** database stuff **********
196
240
197
	public Schema getDbSchema() {
241
	public Schema getDbSchema() {
(-)src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmIdMapping.java (-2 / +31 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2006, 2012 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 28-36 Link Here
28
import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentAttribute;
28
import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentAttribute;
29
import org.eclipse.jpt.jpa.core.context.orm.OrmTemporalConverter;
29
import org.eclipse.jpt.jpa.core.context.orm.OrmTemporalConverter;
30
import org.eclipse.jpt.jpa.core.context.orm.OrmXmlContextNodeFactory;
30
import org.eclipse.jpt.jpa.core.context.orm.OrmXmlContextNodeFactory;
31
import org.eclipse.jpt.jpa.core.internal.context.TableColumnTextRangeResolver;
32
import org.eclipse.jpt.jpa.core.internal.context.JptValidator;
31
import org.eclipse.jpt.jpa.core.internal.context.JptValidator;
33
import org.eclipse.jpt.jpa.core.internal.context.NamedColumnTextRangeResolver;
32
import org.eclipse.jpt.jpa.core.internal.context.NamedColumnTextRangeResolver;
33
import org.eclipse.jpt.jpa.core.internal.context.TableColumnTextRangeResolver;
34
import org.eclipse.jpt.jpa.core.internal.jpa1.context.EntityTableDescriptionProvider;
34
import org.eclipse.jpt.jpa.core.internal.jpa1.context.EntityTableDescriptionProvider;
35
import org.eclipse.jpt.jpa.core.internal.jpa1.context.NamedColumnValidator;
35
import org.eclipse.jpt.jpa.core.internal.jpa1.context.NamedColumnValidator;
36
import org.eclipse.jpt.jpa.core.internal.jpa1.context.orm.NullOrmConverter;
36
import org.eclipse.jpt.jpa.core.internal.jpa1.context.orm.NullOrmConverter;
Lines 449-452 Link Here
449
	public JptValidator buildColumnValidator(ReadOnlyNamedColumn col, NamedColumnTextRangeResolver textRangeResolver) {
449
	public JptValidator buildColumnValidator(ReadOnlyNamedColumn col, NamedColumnTextRangeResolver textRangeResolver) {
450
		return new NamedColumnValidator(this.getPersistentAttribute(), (ReadOnlyBaseColumn) col, (TableColumnTextRangeResolver) textRangeResolver, new EntityTableDescriptionProvider());
450
		return new NamedColumnValidator(this.getPersistentAttribute(), (ReadOnlyBaseColumn) col, (TableColumnTextRangeResolver) textRangeResolver, new EntityTableDescriptionProvider());
451
	}
451
	}
452
453
	// ********** completion proposals **********
454
455
	@Override
456
	public Iterable<String> getXmlCompletionProposals(int pos) {
457
		Iterable<String> result = super.getXmlCompletionProposals(pos);
458
		if (result != null) {
459
			return result;
460
		}
461
		result = this.column.getXmlCompletionProposals(pos);
462
		if (result != null) {
463
			return result;
464
		}
465
		result = this.generatorContainer.getXmlCompletionProposals(pos);
466
		if (result != null) {
467
			return result;
468
		}
469
		if (this.generatedValue != null) {
470
			result = this.generatedValue.getXmlCompletionProposals(pos);
471
			if (result != null) {
472
				return result;
473
			}
474
		}
475
		result = this.converter.getXmlCompletionProposals(pos);
476
		if (result != null) {
477
			return result;
478
		}
479
		return null;
480
	}
452
}
481
}
(-)src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmJoinColumnRelationshipStrategy.java (-1 / +18 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2009, 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2009, 2012 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 290-293 Link Here
290
			joinColumn.validate(messages, reporter);
290
			joinColumn.validate(messages, reporter);
291
		}
291
		}
292
	}
292
	}
293
294
	// ********** completion proposals **********
295
296
	@Override
297
	public Iterable<String> getXmlCompletionProposals(int pos) {
298
		Iterable<String> result = super.getXmlCompletionProposals(pos);
299
		if (result != null) {
300
			return result;
301
		}
302
		for (OrmJoinColumn joinColumn : this.getJoinColumns()) {
303
			result = joinColumn.getXmlCompletionProposals(pos);
304
			if (result != null) {
305
				return result;
306
			}
307
		}
308
		return null;
309
	}
293
}
310
}
(-)src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmJoinTableRelationshipStrategy.java (-1 / +15 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2009, 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2009, 2012 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 126-131 Link Here
126
		}
126
		}
127
	}
127
	}
128
128
129
	// ********** completion proposals **********
130
131
	@Override
132
	public Iterable<String> getXmlCompletionProposals(int pos) {
133
		Iterable<String> result = super.getXmlCompletionProposals(pos);
134
		if (result != null) {
135
			return result;
136
		}
137
		if (this.joinTable != null) {
138
			result = this.joinTable.getXmlCompletionProposals(pos);
139
		}
140
		return result;
141
	}
142
129
143
130
	// ********** misc **********
144
	// ********** misc **********
131
145
(-)src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmMultiRelationshipMapping.java (-1 / +41 lines)
Lines 1070-1075 Link Here
1070
		return this.getValidationTextRange(this.xmlAttributeMapping.getMapKeyClassTextRange());
1070
		return this.getValidationTextRange(this.xmlAttributeMapping.getMapKeyClassTextRange());
1071
	}
1071
	}
1072
1072
1073
	// ********** completion proposals **********
1074
1075
	@Override
1076
	public Iterable<String> getXmlCompletionProposals(int pos) {
1077
		Iterable<String> result = super.getXmlCompletionProposals(pos);
1078
		if (result != null) {
1079
			return result;
1080
		}
1081
		result = this.orderable.getXmlCompletionProposals(pos);
1082
		if (result != null) {
1083
			return result;
1084
		}
1085
		if (this.mapKeyNameTouches(pos)) {
1086
			return this.getCandidateMapKeyNames();
1087
		}
1088
		result = this.mapKeyColumn.getXmlCompletionProposals(pos);
1089
		if (result != null) {
1090
			return result;
1091
		}
1092
		result = this.mapKeyConverter.getXmlCompletionProposals(pos);
1093
		if (result != null) {
1094
			return result;
1095
		}
1096
		result = this.mapKeyAttributeOverrideContainer.getXmlCompletionProposals(pos);
1097
		if (result != null) {
1098
			return result;
1099
		}
1100
		for (OrmJoinColumn joinColumn : this.getMapKeyJoinColumns()) {
1101
			result = joinColumn.getXmlCompletionProposals(pos);
1102
			if (result != null) {
1103
				return result;
1104
			}
1105
		}
1106
		return null;
1107
	}
1108
1109
	protected boolean mapKeyNameTouches(int pos) {
1110
		return this.xmlAttributeMapping.mapKeyNameTouches(pos);
1111
	}
1073
1112
1074
	// ********** abstract owner **********
1113
	// ********** abstract owner **********
1075
1114
Lines 1234-1240 Link Here
1234
		}
1273
		}
1235
1274
1236
		public Table getReferencedColumnDbTable() {
1275
		public Table getReferencedColumnDbTable() {
1237
			return AbstractOrmMultiRelationshipMapping.this.getResolvedMapKeyEntity().getPrimaryDbTable();
1276
			Entity entity = AbstractOrmMultiRelationshipMapping.this.getResolvedMapKeyEntity();
1277
			return entity != null ? entity.getPrimaryDbTable() : null;
1238
		}
1278
		}
1239
1279
1240
		public int getJoinColumnsSize() {
1280
		public int getJoinColumnsSize() {
(-)src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmNamedColumn.java (+24 lines)
Lines 11-16 Link Here
11
11
12
import java.util.List;
12
import java.util.List;
13
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.iterables.EmptyIterable;
14
import org.eclipse.jpt.jpa.core.context.ReadOnlyNamedColumn;
15
import org.eclipse.jpt.jpa.core.context.ReadOnlyNamedColumn;
15
import org.eclipse.jpt.jpa.core.context.XmlContextNode;
16
import org.eclipse.jpt.jpa.core.context.XmlContextNode;
16
import org.eclipse.jpt.jpa.core.context.orm.OrmNamedColumn;
17
import org.eclipse.jpt.jpa.core.context.orm.OrmNamedColumn;
Lines 252-258 Link Here
252
		return (xmlColumn == null) ? null : xmlColumn.getNameTextRange();
253
		return (xmlColumn == null) ? null : xmlColumn.getNameTextRange();
253
	}
254
	}
254
255
256
	// ********** completion proposals **********
255
257
258
	@Override
259
	protected Iterable<String> getConnectedXmlCompletionProposals(int pos) {
260
		Iterable<String> result = super.getConnectedXmlCompletionProposals(pos);
261
		if (result != null) {
262
			return result;
263
		}
264
		if (this.columnNameTouches(pos)) {
265
			return this.getCandidateColumnNames();
266
		}
267
		return null;
268
	}
269
270
	protected boolean columnNameTouches(int pos) {
271
		X column = this.getXmlColumn();
272
		return (column != null) && (column.columnNameTouches(pos));
273
	}
274
275
	protected Iterable<String> getCandidateColumnNames() {
276
		Table dbTable = this.getDbTable();
277
		return (dbTable != null) ? dbTable.getSortedColumnIdentifiers() : EmptyIterable.<String> instance();
278
	}
279
	
256
	// ********** misc **********
280
	// ********** misc **********
257
281
258
	@Override
282
	@Override
(-)src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmRelationshipMapping.java (+15 lines)
Lines 441-445 Link Here
441
	public String getMetamodelTypeName() {
441
	public String getMetamodelTypeName() {
442
		return (this.fullyQualifiedTargetEntity != null) ? this.fullyQualifiedTargetEntity : MetamodelField.DEFAULT_TYPE_NAME;
442
		return (this.fullyQualifiedTargetEntity != null) ? this.fullyQualifiedTargetEntity : MetamodelField.DEFAULT_TYPE_NAME;
443
	}
443
	}
444
	
445
	// ********** completion proposals **********
446
447
	@Override
448
	public Iterable<String> getXmlCompletionProposals(int pos) {
449
		Iterable<String> result = super.getXmlCompletionProposals(pos);
450
		if (result != null) {
451
			return result;
452
		}
453
		result = this.relationship.getXmlCompletionProposals(pos);
454
		if (result != null) {
455
			return result;
456
		}
457
		return null;
458
	}
444
459
445
}
460
}
(-)src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmSequenceGenerator.java (-1 / +31 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2010 Oracle. All rights reserved.
2
 * Copyright (c) 2007, 2012 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 10-20 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 org.eclipse.jpt.common.utility.internal.StringTools;
12
import org.eclipse.jpt.common.utility.internal.StringTools;
13
import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable;
13
import org.eclipse.jpt.jpa.core.context.Generator;
14
import org.eclipse.jpt.jpa.core.context.Generator;
14
import org.eclipse.jpt.jpa.core.context.SequenceGenerator;
15
import org.eclipse.jpt.jpa.core.context.SequenceGenerator;
15
import org.eclipse.jpt.jpa.core.context.XmlContextNode;
16
import org.eclipse.jpt.jpa.core.context.XmlContextNode;
16
import org.eclipse.jpt.jpa.core.context.orm.OrmSequenceGenerator;
17
import org.eclipse.jpt.jpa.core.context.orm.OrmSequenceGenerator;
17
import org.eclipse.jpt.jpa.core.resource.orm.XmlSequenceGenerator;
18
import org.eclipse.jpt.jpa.core.resource.orm.XmlSequenceGenerator;
19
import org.eclipse.jpt.jpa.db.Schema;
18
20
19
/**
21
/**
20
 * <code>orm.xml</code> sequence generator
22
 * <code>orm.xml</code> sequence generator
Lines 104-107 Link Here
104
		return super.isIdentical(generator) &&
106
		return super.isIdentical(generator) &&
105
				StringTools.stringsAreEqual(this.getSpecifiedSequenceName(), ((SequenceGenerator)generator).getSpecifiedSequenceName());
107
				StringTools.stringsAreEqual(this.getSpecifiedSequenceName(), ((SequenceGenerator)generator).getSpecifiedSequenceName());
106
	}
108
	}
109
	
110
	// ********** completion proposals **********
111
112
	/**
113
	 * called if the database is connected:
114
	 * sequenceName
115
	 */
116
	@Override
117
	protected Iterable<String> getConnectedXmlCompletionProposals(int pos) {
118
		Iterable<String> result = super.getConnectedXmlCompletionProposals(pos);
119
		if (result != null) {
120
			return result;
121
		}
122
		if (this.sequenceNameTouches(pos)) {
123
			return this.getCandidateSequences();
124
		}
125
		return null;
126
	}
127
128
	protected boolean sequenceNameTouches(int pos) {
129
		return this.xmlGenerator.sequenceNameTouches(pos);
130
	}
131
132
	protected Iterable<String> getCandidateSequences() {
133
		Schema dbSchema = this.getDbSchema();
134
		return (dbSchema != null) ? dbSchema.getSortedSequenceIdentifiers() : EmptyIterable.<String> instance();
135
	}
136
107
}
137
}
(-)src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmSingleRelationshipMapping.java (-1 / +16 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2006, 2012 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 138-141 Link Here
138
		super.validate(messages, reporter);
138
		super.validate(messages, reporter);
139
		this.derivedIdentity.validate(messages, reporter);
139
		this.derivedIdentity.validate(messages, reporter);
140
	}
140
	}
141
142
	// ********** completion proposals **********
143
144
	@Override
145
	public Iterable<String> getXmlCompletionProposals(int pos) {
146
		Iterable<String> result = super.getXmlCompletionProposals(pos);
147
		if (result != null) {
148
			return result;
149
		}
150
		result = this.derivedIdentity.getXmlCompletionProposals(pos);
151
		if (result != null) {
152
			return result;
153
		}
154
		return null;
155
	}
141
}
156
}
(-)src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmTable.java (-1 / +78 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2007, 2012 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 28-33 Link Here
28
import org.eclipse.jpt.jpa.core.resource.orm.OrmFactory;
28
import org.eclipse.jpt.jpa.core.resource.orm.OrmFactory;
29
import org.eclipse.jpt.jpa.core.resource.orm.XmlUniqueConstraint;
29
import org.eclipse.jpt.jpa.core.resource.orm.XmlUniqueConstraint;
30
import org.eclipse.jpt.jpa.db.Catalog;
30
import org.eclipse.jpt.jpa.db.Catalog;
31
import org.eclipse.jpt.jpa.db.Database;
31
import org.eclipse.jpt.jpa.db.Schema;
32
import org.eclipse.jpt.jpa.db.Schema;
32
import org.eclipse.jpt.jpa.db.SchemaContainer;
33
import org.eclipse.jpt.jpa.db.SchemaContainer;
33
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
34
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
Lines 469-474 Link Here
469
		return (xmlTable == null) ? null : xmlTable.getCatalogTextRange();
470
		return (xmlTable == null) ? null : xmlTable.getCatalogTextRange();
470
	}
471
	}
471
472
473
	// ********** completion proposals **********
474
475
	@Override
476
	public Iterable<String> getXmlCompletionProposals(int pos) {
477
		Iterable<String> result = super.getXmlCompletionProposals(pos);
478
		if (result != null) {
479
			return result;
480
		}
481
		for (OrmUniqueConstraint constraint : this.getUniqueConstraints()) {
482
			result = constraint.getXmlCompletionProposals(pos);
483
			if (result != null) {
484
				return result;
485
			}
486
		}
487
		return null;
488
	}
489
490
	/**
491
	 * called if the database is connected:
492
	 * name, schema, catalog
493
	 */
494
	@Override
495
	protected Iterable<String> getConnectedXmlCompletionProposals(int pos) {
496
		Iterable<String> result = super.getConnectedXmlCompletionProposals(pos);
497
		if (result != null) {
498
			return result;
499
		}
500
		if (this.tableNameTouches(pos)) {
501
			return this.getCandidateTableNames();
502
		}
503
		if (this.schemaTouches(pos)) {
504
			return this.getCandidateSchemata();
505
		}
506
		if (this.catalogTouches(pos)) {
507
			return this.getCandidateCatalogs();
508
		}
509
		return null;
510
	}
511
512
	// ********* content assist : table
513
	
514
	protected boolean tableNameTouches(int pos) {
515
		X table = this.getXmlTable();
516
		return (table != null) && (table.nameTouches(pos));
517
	}
518
519
	protected Iterable<String> getCandidateTableNames() {
520
		Schema dbSchema = this.getDbSchema();
521
		return (dbSchema != null) ? dbSchema.getSortedTableIdentifiers() : EmptyIterable.<String> instance();
522
	}
523
524
	// ********* content assist : schema
525
	
526
	protected boolean schemaTouches(int pos) {
527
		X table = this.getXmlTable();
528
		return (table != null) && (table.schemaTouches(pos));
529
	}
530
531
	protected Iterable<String> getCandidateSchemata() {
532
		if (this.getDbSchemaContainer() == null)
533
			return EmptyIterable.<String>instance();
534
		else
535
			return this.getDbSchemaContainer().getSortedSchemaIdentifiers();
536
	}
537
538
	// ********* content assist : catalog
539
	
540
	protected boolean catalogTouches(int pos) {
541
		X table = this.getXmlTable();
542
		return (table != null) && (table.catalogTouches(pos));
543
	}
544
545
	protected Iterable<String> getCandidateCatalogs() {
546
		Database db = this.getDatabase();
547
		return (db != null) ? db.getSortedCatalogIdentifiers() : EmptyIterable.<String> instance();
548
	}
472
549
473
	// ********** misc **********
550
	// ********** misc **********
474
551
(-)src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmTypeMapping.java (+54 lines)
Lines 605-608 Link Here
605
		//fix this problem.  bug 358745
605
		//fix this problem.  bug 358745
606
		return (textRange != null) ? textRange : TextRange.Empty.instance();
606
		return (textRange != null) ? textRange : TextRange.Empty.instance();
607
	}
607
	}
608
609
	// ********** completion proposals **********
610
611
	@Override
612
	public Iterable<String> getXmlCompletionProposals(int pos) {
613
		Iterable<String> result = super.getXmlCompletionProposals(pos);
614
		if (result != null) {
615
			return result;
616
		}
617
		if (this.classNameTouches(pos)) {
618
			return this.getCandidateClassNames();
619
		}
620
		return null;
621
	}
622
623
	private Iterable<String> getCandidateClassNames() {
624
		final String packageName = this.getEntityMappings().getPackage();
625
		if (!StringTools.stringIsEmpty(packageName)) {
626
			return new TransformationIterable<String, String>(this.getFilteredCandidateClassNames(packageName)) {
627
				@Override
628
				protected String transform(String className) {
629
					return className.substring(packageName.length()+1);
630
				}
631
			};
632
		}
633
		return this.getCandidateFullQulifiedClassNames();
634
	}
635
	
636
	private Iterable<String> getFilteredCandidateClassNames(final String packageName) {
637
			return new FilteringIterable<String>(this.getCandidateFullQulifiedClassNames()) {
638
				@Override
639
				protected boolean accept(String className) {
640
					return className.startsWith(packageName);
641
				}
642
			};
643
	}
644
645
	/**
646
	 * @return names of the classes specified by class refs and jar files
647
	 */
648
	// should return names of all the classes defined in the project?
649
	private Iterable<String> getCandidateFullQulifiedClassNames() {
650
		return new TransformationIterable<PersistentType, String>(
651
				this.getPersistenceUnit().getJavaPersistentTypes()) {
652
			@Override
653
			protected String transform(PersistentType pType) {
654
				return pType.getName();
655
			}
656
		};
657
	}
658
659
	private boolean classNameTouches(int pos) {
660
		return this.getXmlTypeMapping().classNameTouches(pos);
661
	}
608
}
662
}
(-)src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmVersionMapping.java (-1 / +20 lines)
Lines 24-32 Link Here
24
import org.eclipse.jpt.jpa.core.context.orm.OrmTemporalConverter;
24
import org.eclipse.jpt.jpa.core.context.orm.OrmTemporalConverter;
25
import org.eclipse.jpt.jpa.core.context.orm.OrmVersionMapping;
25
import org.eclipse.jpt.jpa.core.context.orm.OrmVersionMapping;
26
import org.eclipse.jpt.jpa.core.context.orm.OrmXmlContextNodeFactory;
26
import org.eclipse.jpt.jpa.core.context.orm.OrmXmlContextNodeFactory;
27
import org.eclipse.jpt.jpa.core.internal.context.TableColumnTextRangeResolver;
28
import org.eclipse.jpt.jpa.core.internal.context.JptValidator;
27
import org.eclipse.jpt.jpa.core.internal.context.JptValidator;
29
import org.eclipse.jpt.jpa.core.internal.context.NamedColumnTextRangeResolver;
28
import org.eclipse.jpt.jpa.core.internal.context.NamedColumnTextRangeResolver;
29
import org.eclipse.jpt.jpa.core.internal.context.TableColumnTextRangeResolver;
30
import org.eclipse.jpt.jpa.core.internal.jpa1.context.EntityTableDescriptionProvider;
30
import org.eclipse.jpt.jpa.core.internal.jpa1.context.EntityTableDescriptionProvider;
31
import org.eclipse.jpt.jpa.core.internal.jpa1.context.NamedColumnValidator;
31
import org.eclipse.jpt.jpa.core.internal.jpa1.context.NamedColumnValidator;
32
import org.eclipse.jpt.jpa.core.internal.jpa1.context.orm.NullOrmConverter;
32
import org.eclipse.jpt.jpa.core.internal.jpa1.context.orm.NullOrmConverter;
Lines 291-294 Link Here
291
	public JptValidator buildColumnValidator(ReadOnlyNamedColumn col, NamedColumnTextRangeResolver textRangeResolver) {
291
	public JptValidator buildColumnValidator(ReadOnlyNamedColumn col, NamedColumnTextRangeResolver textRangeResolver) {
292
		return new NamedColumnValidator(this.getPersistentAttribute(), (ReadOnlyBaseColumn) col, (TableColumnTextRangeResolver) textRangeResolver, new EntityTableDescriptionProvider());
292
		return new NamedColumnValidator(this.getPersistentAttribute(), (ReadOnlyBaseColumn) col, (TableColumnTextRangeResolver) textRangeResolver, new EntityTableDescriptionProvider());
293
	}
293
	}
294
295
	// ********** completion proposals **********
296
297
	@Override
298
	public Iterable<String> getXmlCompletionProposals(int pos) {
299
		Iterable<String> result = super.getXmlCompletionProposals(pos);
300
		if (result != null) {
301
			return result;
302
		}
303
		result = this.column.getXmlCompletionProposals(pos);
304
		if (result != null) {
305
			return result;
306
		}
307
		result = this.converter.getXmlCompletionProposals(pos);
308
		if (result != null) {
309
			return result;
310
		}
311
		return null;
312
	}
294
}
313
}
(-)src/org/eclipse/jpt/jpa/core/internal/context/orm/GenericOrmManyToManyRelationship.java (-1 / +20 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2009, 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2009, 2012 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 171-174 Link Here
171
		this.mappedByStrategy.validate(messages, reporter);
171
		this.mappedByStrategy.validate(messages, reporter);
172
		this.joinTableStrategy.validate(messages, reporter);
172
		this.joinTableStrategy.validate(messages, reporter);
173
	}
173
	}
174
175
	// ********** completion proposals **********
176
177
	@Override
178
	public Iterable<String> getXmlCompletionProposals(int pos) {
179
		Iterable<String> result = super.getXmlCompletionProposals(pos);
180
		if (result != null) {
181
			return result;
182
		}
183
		result = this.mappedByStrategy.getXmlCompletionProposals(pos);
184
		if (result != null) {
185
			return result;
186
		}
187
		result = this.joinTableStrategy.getXmlCompletionProposals(pos);
188
		if (result != null) {
189
			return result;
190
		}
191
		return null;
192
	}
174
}
193
}
(-)src/org/eclipse/jpt/jpa/core/internal/context/orm/GenericOrmManyToOneRelationship.java (-1 / +20 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2009, 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2009, 2012 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 176-179 Link Here
176
		this.joinColumnStrategy.validate(messages, reporter);
176
		this.joinColumnStrategy.validate(messages, reporter);
177
		this.joinTableStrategy.validate(messages, reporter);
177
		this.joinTableStrategy.validate(messages, reporter);
178
	}
178
	}
179
180
	// ********** completion proposals **********
181
182
	@Override
183
	public Iterable<String> getXmlCompletionProposals(int pos) {
184
		Iterable<String> result = super.getXmlCompletionProposals(pos);
185
		if (result != null) {
186
			return result;
187
		}
188
		result = this.joinColumnStrategy.getXmlCompletionProposals(pos);
189
		if (result != null) {
190
			return result;
191
		}
192
		result = this.joinTableStrategy.getXmlCompletionProposals(pos);
193
		if (result != null) {
194
			return result;
195
		}
196
		return null;
197
	}
179
}
198
}
(-)src/org/eclipse/jpt/jpa/core/internal/context/orm/GenericOrmMappedByRelationshipStrategy.java (-1 / +19 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2009, 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2009, 2012 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 222-225 Link Here
222
		TextRange textRange = this.getXmlMappedByMapping().getMappedByTextRange();
222
		TextRange textRange = this.getXmlMappedByMapping().getMappedByTextRange();
223
		return (textRange != null) ? textRange : this.getRelationship().getValidationTextRange();
223
		return (textRange != null) ? textRange : this.getRelationship().getValidationTextRange();
224
	}
224
	}
225
226
	// ********** completion proposals **********
227
228
	@Override
229
	public Iterable<String> getXmlCompletionProposals(int pos) {
230
		Iterable<String> result = super.getXmlCompletionProposals(pos);
231
		if (result != null) {
232
			return result;
233
		}
234
		if (this.mappedByTouches(pos)) {
235
			return this.getCandidateMappedByAttributeNames();
236
		}
237
		return null;
238
	}
239
	
240
	protected boolean mappedByTouches(int pos) {
241
		return this.getXmlMappedByMapping().mappedByTouches(pos);
242
	}
225
}
243
}
(-)src/org/eclipse/jpt/jpa/core/internal/context/orm/GenericOrmOneToManyRelationship.java (-1 / +24 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2009, 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2009, 2012 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 241-244 Link Here
241
		this.joinTableStrategy.validate(messages, reporter);
241
		this.joinTableStrategy.validate(messages, reporter);
242
		this.joinColumnStrategy.validate(messages, reporter);
242
		this.joinColumnStrategy.validate(messages, reporter);
243
	}
243
	}
244
245
	// ********** completion proposals **********
246
247
	@Override
248
	public Iterable<String> getXmlCompletionProposals(int pos) {
249
		Iterable<String> result = super.getXmlCompletionProposals(pos);
250
		if (result != null) {
251
			return result;
252
		}
253
		result = this.mappedByStrategy.getXmlCompletionProposals(pos);
254
		if (result != null) {
255
			return result;
256
		}
257
		result = this.joinTableStrategy.getXmlCompletionProposals(pos);
258
		if (result != null) {
259
			return result;
260
		}
261
		result = this.joinColumnStrategy.getXmlCompletionProposals(pos);
262
		if (result != null) {
263
			return result;
264
		}
265
		return null;
266
	}
244
}
267
}
(-)src/org/eclipse/jpt/jpa/core/internal/context/orm/GenericOrmOneToOneRelationship.java (-1 / +28 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2009, 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2009, 2012 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 264-267 Link Here
264
		this.joinTableStrategy.validate(messages, reporter);
264
		this.joinTableStrategy.validate(messages, reporter);
265
		this.joinColumnStrategy.validate(messages, reporter);
265
		this.joinColumnStrategy.validate(messages, reporter);
266
	}
266
	}
267
268
	// ********** completion proposals **********
269
270
	@Override
271
	public Iterable<String> getXmlCompletionProposals(int pos) {
272
		Iterable<String> result = super.getXmlCompletionProposals(pos);
273
		if (result != null) {
274
			return result;
275
		}
276
		result = this.mappedByStrategy.getXmlCompletionProposals(pos);
277
		if (result != null) {
278
			return result;
279
		}
280
		result = this.primaryKeyJoinColumnStrategy.getXmlCompletionProposals(pos);
281
		if (result != null) {
282
			return result;
283
		}
284
		result = this.joinTableStrategy.getXmlCompletionProposals(pos);
285
		if (result != null) {
286
			return result;
287
		}
288
		result = this.joinColumnStrategy.getXmlCompletionProposals(pos);
289
		if (result != null) {
290
			return result;
291
		}
292
		return null;
293
	}
267
}
294
}
(-)src/org/eclipse/jpt/jpa/core/internal/context/orm/GenericOrmPrimaryKeyJoinColumnRelationshipStrategy.java (+16 lines)
Lines 238-243 Link Here
238
		}
238
		}
239
	}
239
	}
240
240
241
	// ********** completion proposals **********
242
243
	@Override
244
	public Iterable<String> getXmlCompletionProposals(int pos) {
245
		Iterable<String> result = super.getXmlCompletionProposals(pos);
246
		if (result != null) {
247
			return result;
248
		}
249
		for (OrmPrimaryKeyJoinColumn column : this.getPrimaryKeyJoinColumns()) {
250
			result = column.getXmlCompletionProposals(pos);
251
			if (result != null) {
252
				return result;
253
			}
254
		}
255
		return null;
256
	}
241
257
242
	// ********** join column owner **********
258
	// ********** join column owner **********
243
259
(-)src/org/eclipse/jpt/jpa/core/internal/context/orm/SpecifiedOrmPersistentAttribute.java (+14 lines)
Lines 533-538 Link Here
533
				JavaPersistentAttribute.JpaContainerDefinition.Null.instance();
533
				JavaPersistentAttribute.JpaContainerDefinition.Null.instance();
534
	}
534
	}
535
535
536
	// ********** completion proposals **********
537
538
	@Override
539
	public Iterable<String> getXmlCompletionProposals(int pos) {
540
		Iterable<String> result = super.getXmlCompletionProposals(pos);
541
		if (result != null) {
542
			return result;
543
		}
544
		result = this.mapping.getXmlCompletionProposals(pos);
545
		if (result != null) {
546
			return result;
547
		}
548
		return null;
549
	}
536
550
537
	// ********** misc **********
551
	// ********** misc **********
538
552
(-)src/org/eclipse/jpt/jpa/core/internal/context/orm/SpecifiedOrmPersistentType.java (+20 lines)
Lines 1293-1298 Link Here
1293
		return this.mapping.getValidationTextRange();
1293
		return this.mapping.getValidationTextRange();
1294
	}
1294
	}
1295
1295
1296
	// ********** completion proposals **********
1297
	
1298
	@Override
1299
	public Iterable<String> getXmlCompletionProposals(int pos) {
1300
		Iterable<String> result = super.getXmlCompletionProposals(pos);
1301
		if (result != null) {
1302
			return result;
1303
		}
1304
		result = this.mapping.getXmlCompletionProposals(pos);
1305
		if (result != null) {
1306
			return result;
1307
		}
1308
		for (OrmPersistentAttribute attribute : this.getSpecifiedAttributes()) {
1309
			result = attribute.getXmlCompletionProposals(pos);
1310
			if (result != null) {
1311
				return result;
1312
			}
1313
		}
1314
		return null;
1315
	}
1296
1316
1297
	// ********** misc **********
1317
	// ********** misc **********
1298
1318
(-)src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractPersistenceUnit.java (-8 / +10 lines)
Lines 31-36 Link Here
31
import org.eclipse.jdt.core.IType;
31
import org.eclipse.jdt.core.IType;
32
import org.eclipse.jdt.core.JavaModelException;
32
import org.eclipse.jdt.core.JavaModelException;
33
import org.eclipse.jpt.common.core.resource.java.JavaResourceAbstractType;
33
import org.eclipse.jpt.common.core.resource.java.JavaResourceAbstractType;
34
import org.eclipse.jpt.common.core.resource.java.JavaResourceType;
34
import org.eclipse.jpt.common.core.utility.BodySourceWriter;
35
import org.eclipse.jpt.common.core.utility.BodySourceWriter;
35
import org.eclipse.jpt.common.core.utility.TextRange;
36
import org.eclipse.jpt.common.core.utility.TextRange;
36
import org.eclipse.jpt.common.utility.internal.CollectionTools;
37
import org.eclipse.jpt.common.utility.internal.CollectionTools;
Lines 1657-1671 Link Here
1657
				);
1658
				);
1658
	}
1659
	}
1659
1660
1660
	/**
1661
	 * Return the persistence unit's Java persistent types, as specified by
1662
	 * the class refs (both specified and implied) and jar files.
1663
	 * There can be duplicate types, and any of them may be overridden by a
1664
	 * mapping file persistence type.
1665
	 * @see #getMappingFilePersistentTypes()
1666
	 */
1667
	@SuppressWarnings("unchecked")
1661
	@SuppressWarnings("unchecked")
1668
	protected Iterable<PersistentType> getJavaPersistentTypes() {
1662
	public Iterable<PersistentType> getJavaPersistentTypes() {
1669
		return new CompositeIterable<PersistentType>(
1663
		return new CompositeIterable<PersistentType>(
1670
				this.getClassRefPersistentTypes(),
1664
				this.getClassRefPersistentTypes(),
1671
				this.getJarFilePersistentTypes()
1665
				this.getJarFilePersistentTypes()
Lines 2043-2048 Link Here
2043
		sb.append(this.name);
2037
		sb.append(this.name);
2044
	}
2038
	}
2045
2039
2040
	public Iterable<String> getPackageNames() {
2041
		Set<String> packageNames = new HashSet<String>();
2042
		for (PersistentType pType : this.getJavaPersistentTypes()) {
2043
			JavaResourceType jrt = ((JavaPersistentType)pType).getJavaResourceType();
2044
			packageNames.add(jrt.getPackageName());
2045
		}
2046
		return packageNames;
2047
	}
2046
2048
2047
	// ********** validation **********
2049
	// ********** validation **********
2048
2050
(-)src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/AbstractOrmEmbeddedMapping.java (+14 lines)
Lines 220-225 Link Here
220
		this.associationOverrideContainer.validate(messages, reporter);
220
		this.associationOverrideContainer.validate(messages, reporter);
221
	}
221
	}
222
222
223
	// ********** completion proposals **********
224
	
225
	@Override
226
	public Iterable<String> getXmlCompletionProposals(int pos) {
227
		Iterable<String> result = super.getXmlCompletionProposals(pos);
228
		if (result != null) {
229
			return result;
230
		}
231
		result = this.associationOverrideContainer.getXmlCompletionProposals(pos);
232
		if (result != null) {
233
			return result;
234
		}
235
		return null;
236
	}
223
237
224
	// ********** attribute override container owner *********
238
	// ********** attribute override container owner *********
225
239
(-)src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/AbstractOrmOverride.java (-3 / +25 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2007, 2012 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 13-26 Link Here
13
import org.eclipse.jpt.common.core.utility.TextRange;
13
import org.eclipse.jpt.common.core.utility.TextRange;
14
import org.eclipse.jpt.jpa.core.context.ReadOnlyBaseColumn;
14
import org.eclipse.jpt.jpa.core.context.ReadOnlyBaseColumn;
15
import org.eclipse.jpt.jpa.core.context.ReadOnlyOverride;
15
import org.eclipse.jpt.jpa.core.context.ReadOnlyOverride;
16
import org.eclipse.jpt.jpa.core.context.TypeMapping;
17
import org.eclipse.jpt.jpa.core.context.ReadOnlyTableColumn.Owner;
16
import org.eclipse.jpt.jpa.core.context.ReadOnlyTableColumn.Owner;
17
import org.eclipse.jpt.jpa.core.context.TypeMapping;
18
import org.eclipse.jpt.jpa.core.context.orm.OrmOverride;
18
import org.eclipse.jpt.jpa.core.context.orm.OrmOverride;
19
import org.eclipse.jpt.jpa.core.context.orm.OrmOverrideContainer;
19
import org.eclipse.jpt.jpa.core.context.orm.OrmOverrideContainer;
20
import org.eclipse.jpt.jpa.core.context.orm.OrmVirtualOverride;
20
import org.eclipse.jpt.jpa.core.context.orm.OrmVirtualOverride;
21
import org.eclipse.jpt.jpa.core.internal.context.TableColumnTextRangeResolver;
22
import org.eclipse.jpt.jpa.core.internal.context.JptValidator;
21
import org.eclipse.jpt.jpa.core.internal.context.JptValidator;
23
import org.eclipse.jpt.jpa.core.internal.context.OverrideTextRangeResolver;
22
import org.eclipse.jpt.jpa.core.internal.context.OverrideTextRangeResolver;
23
import org.eclipse.jpt.jpa.core.internal.context.TableColumnTextRangeResolver;
24
import org.eclipse.jpt.jpa.core.internal.context.orm.AbstractOrmXmlContextNode;
24
import org.eclipse.jpt.jpa.core.internal.context.orm.AbstractOrmXmlContextNode;
25
import org.eclipse.jpt.jpa.core.internal.context.orm.OrmOverrideTextRangeResolver;
25
import org.eclipse.jpt.jpa.core.internal.context.orm.OrmOverrideTextRangeResolver;
26
import org.eclipse.jpt.jpa.core.resource.orm.XmlOverride;
26
import org.eclipse.jpt.jpa.core.resource.orm.XmlOverride;
Lines 170-173 Link Here
170
	public Iterable<String> getCandidateTableNames() {
170
	public Iterable<String> getCandidateTableNames() {
171
		return this.getContainer().getCandidateTableNames();
171
		return this.getContainer().getCandidateTableNames();
172
	}
172
	}
173
174
	// ********** completion proposals **********
175
176
	@Override
177
	public Iterable<String> getXmlCompletionProposals(int pos) {
178
		Iterable<String> result = super.getXmlCompletionProposals(pos);
179
		if (result != null) {
180
			return result;
181
		}
182
		if (this.nameTouches(pos)) {
183
			return this.getCandidateNames();
184
		}
185
		return null;
186
	}
187
188
	protected boolean nameTouches(int pos) {
189
		return this.xmlOverride.nameTouches(pos);
190
	}
191
192
	protected Iterable<String> getCandidateNames() {
193
		return this.getContainer().getAllOverridableNames();
194
	}
173
}
195
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/AbstractOrmOverrideContainer.java (-2 / +19 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2010, 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2010, 2012 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 28-37 Link Here
28
import org.eclipse.jpt.jpa.core.context.orm.OrmOverrideContainer;
28
import org.eclipse.jpt.jpa.core.context.orm.OrmOverrideContainer;
29
import org.eclipse.jpt.jpa.core.context.orm.OrmReadOnlyOverride;
29
import org.eclipse.jpt.jpa.core.context.orm.OrmReadOnlyOverride;
30
import org.eclipse.jpt.jpa.core.context.orm.OrmVirtualOverride;
30
import org.eclipse.jpt.jpa.core.context.orm.OrmVirtualOverride;
31
import org.eclipse.jpt.jpa.core.internal.context.TableColumnTextRangeResolver;
32
import org.eclipse.jpt.jpa.core.internal.context.ContextContainerTools;
31
import org.eclipse.jpt.jpa.core.internal.context.ContextContainerTools;
33
import org.eclipse.jpt.jpa.core.internal.context.JptValidator;
32
import org.eclipse.jpt.jpa.core.internal.context.JptValidator;
34
import org.eclipse.jpt.jpa.core.internal.context.OverrideTextRangeResolver;
33
import org.eclipse.jpt.jpa.core.internal.context.OverrideTextRangeResolver;
34
import org.eclipse.jpt.jpa.core.internal.context.TableColumnTextRangeResolver;
35
import org.eclipse.jpt.jpa.core.internal.context.orm.AbstractOrmXmlContextNode;
35
import org.eclipse.jpt.jpa.core.internal.context.orm.AbstractOrmXmlContextNode;
36
import org.eclipse.jpt.jpa.core.resource.orm.XmlOverride;
36
import org.eclipse.jpt.jpa.core.resource.orm.XmlOverride;
37
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
37
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
Lines 471-474 Link Here
471
				this.specifiedOverrides.get(0).getValidationTextRange() :
471
				this.specifiedOverrides.get(0).getValidationTextRange() :
472
				this.owner.getValidationTextRange();
472
				this.owner.getValidationTextRange();
473
	}
473
	}
474
475
	// ********** completion proposals **********
476
477
	@Override
478
	public Iterable<String> getXmlCompletionProposals(int pos) {
479
		Iterable<String> result = super.getXmlCompletionProposals(pos);
480
		if (result != null) {
481
			return result;
482
		}
483
		for (R override : this.getOverrides()) {
484
			result = override.getXmlCompletionProposals(pos);
485
			if (result != null) {
486
				return result;
487
			}
488
		}
489
		return null;
490
	}
474
}
491
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/AbstractOrmPersistenceUnitDefaults.java (+41 lines)
Lines 10-15 Link Here
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 org.eclipse.jpt.common.core.utility.TextRange;
12
import org.eclipse.jpt.common.core.utility.TextRange;
13
import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable;
13
import org.eclipse.jpt.jpa.core.context.AccessType;
14
import org.eclipse.jpt.jpa.core.context.AccessType;
14
import org.eclipse.jpt.jpa.core.context.orm.OrmPersistenceUnitMetadata;
15
import org.eclipse.jpt.jpa.core.context.orm.OrmPersistenceUnitMetadata;
15
import org.eclipse.jpt.jpa.core.internal.context.orm.AbstractOrmXmlContextNode;
16
import org.eclipse.jpt.jpa.core.internal.context.orm.AbstractOrmXmlContextNode;
Lines 17-22 Link Here
17
import org.eclipse.jpt.jpa.core.resource.orm.XmlPersistenceUnitDefaults;
18
import org.eclipse.jpt.jpa.core.resource.orm.XmlPersistenceUnitDefaults;
18
import org.eclipse.jpt.jpa.core.resource.orm.XmlPersistenceUnitMetadata;
19
import org.eclipse.jpt.jpa.core.resource.orm.XmlPersistenceUnitMetadata;
19
import org.eclipse.jpt.jpa.db.Catalog;
20
import org.eclipse.jpt.jpa.db.Catalog;
21
import org.eclipse.jpt.jpa.db.Database;
20
import org.eclipse.jpt.jpa.db.Schema;
22
import org.eclipse.jpt.jpa.db.Schema;
21
import org.eclipse.jpt.jpa.db.SchemaContainer;
23
import org.eclipse.jpt.jpa.db.SchemaContainer;
22
24
Lines 353-356 Link Here
353
		XmlPersistenceUnitDefaults xmlDefaults = this.getXmlDefaults();
355
		XmlPersistenceUnitDefaults xmlDefaults = this.getXmlDefaults();
354
		return (xmlDefaults == null) ? null : xmlDefaults.getValidationTextRange();
356
		return (xmlDefaults == null) ? null : xmlDefaults.getValidationTextRange();
355
	}
357
	}
358
359
	// ********** completion proposals *********
360
	
361
	@Override
362
	protected Iterable<String> getConnectedXmlCompletionProposals(int pos) {
363
		Iterable<String> result = super.getConnectedXmlCompletionProposals(pos);
364
		if (result != null) {
365
			return result;
366
		}
367
		if (this.schemaTouches(pos)) {
368
			return this.getCandidateSchemata();
369
		}
370
		if (this.catalogTouches(pos)) {
371
			return this.getCandidateCatalogs();
372
		}
373
		return null;
374
	}
375
	
376
	// ********** content assist: schema
377
378
	protected boolean schemaTouches(int pos) {
379
		return (this.getXmlDefaults() != null) && this.getXmlDefaults().schemaTouches(pos);
380
	}
381
382
	protected Iterable<String> getCandidateSchemata() {
383
		SchemaContainer schemaContainer = this.getDbSchemaContainer();
384
		return (schemaContainer != null) ? schemaContainer.getSortedSchemaIdentifiers() : EmptyIterable.<String> instance();
385
	}
386
387
	// ********** content assist: catalog
388
389
	protected boolean catalogTouches(int pos) {
390
		return (this.getXmlDefaults() != null) && this.getXmlDefaults().catalogTouches(pos);
391
	}
392
393
	protected Iterable<String> getCandidateCatalogs() {
394
		Database db = this.getDatabase();
395
		return (db != null) ? db.getSortedCatalogIdentifiers() : EmptyIterable.<String> instance();
396
	}
356
}
397
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/AbstractOrmPersistenceUnitMetadata.java (-1 / +16 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2006, 2012 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 187-190 Link Here
187
		XmlPersistenceUnitMetadata xmlMetadata = this.getXmlPersistenceUnitMetadata();
187
		XmlPersistenceUnitMetadata xmlMetadata = this.getXmlPersistenceUnitMetadata();
188
		return (xmlMetadata == null) ? null : xmlMetadata.getValidationTextRange();
188
		return (xmlMetadata == null) ? null : xmlMetadata.getValidationTextRange();
189
	}
189
	}
190
191
	// ********** completion proposals **********
192
193
	@Override
194
	public Iterable<String> getXmlCompletionProposals(int pos) {
195
		Iterable<String> result = super.getXmlCompletionProposals(pos);
196
		if (result != null) {
197
			return result;
198
		}
199
		result = this.persistenceUnitDefaults.getXmlCompletionProposals(pos);
200
		if (result != null) {
201
			return result;
202
		}
203
		return null;
204
	}
190
}
205
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmAssociationOverride.java (-1 / +16 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2008, 2012 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 116-119 Link Here
116
	public JptValidator buildJoinTableInverseJoinColumnValidator(ReadOnlyJoinColumn column, ReadOnlyJoinColumn.Owner owner, JoinColumnTextRangeResolver textRangeResolver) {
116
	public JptValidator buildJoinTableInverseJoinColumnValidator(ReadOnlyJoinColumn column, ReadOnlyJoinColumn.Owner owner, JoinColumnTextRangeResolver textRangeResolver) {
117
		return this.getContainer2_0().buildJoinTableInverseJoinColumnValidator(this, column, owner, textRangeResolver);
117
		return this.getContainer2_0().buildJoinTableInverseJoinColumnValidator(this, column, owner, textRangeResolver);
118
	}
118
	}
119
120
	// ********** completion proposals **********
121
122
	@Override
123
	public Iterable<String> getXmlCompletionProposals(int pos) {
124
		Iterable<String> result = super.getXmlCompletionProposals(pos);
125
		if (result != null) {
126
			return result;
127
		}
128
		result = this.relationship.getXmlCompletionProposals(pos);
129
		if (result != null) {
130
			return result;
131
		}
132
		return null;
133
	}
119
}
134
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmAttributeOverride.java (-2 / +17 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2007, 2012 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 17-25 Link Here
17
import org.eclipse.jpt.jpa.core.context.orm.OrmAttributeOverrideContainer;
17
import org.eclipse.jpt.jpa.core.context.orm.OrmAttributeOverrideContainer;
18
import org.eclipse.jpt.jpa.core.context.orm.OrmColumn;
18
import org.eclipse.jpt.jpa.core.context.orm.OrmColumn;
19
import org.eclipse.jpt.jpa.core.context.orm.OrmVirtualAttributeOverride;
19
import org.eclipse.jpt.jpa.core.context.orm.OrmVirtualAttributeOverride;
20
import org.eclipse.jpt.jpa.core.internal.context.TableColumnTextRangeResolver;
21
import org.eclipse.jpt.jpa.core.internal.context.JptValidator;
20
import org.eclipse.jpt.jpa.core.internal.context.JptValidator;
22
import org.eclipse.jpt.jpa.core.internal.context.NamedColumnTextRangeResolver;
21
import org.eclipse.jpt.jpa.core.internal.context.NamedColumnTextRangeResolver;
22
import org.eclipse.jpt.jpa.core.internal.context.TableColumnTextRangeResolver;
23
import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages;
23
import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages;
24
import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages;
24
import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages;
25
import org.eclipse.jpt.jpa.core.resource.orm.OrmFactory;
25
import org.eclipse.jpt.jpa.core.resource.orm.OrmFactory;
Lines 152-155 Link Here
152
	protected boolean xmlColumnIsSpecified() {
152
	protected boolean xmlColumnIsSpecified() {
153
		return this.getXmlColumn() != null;
153
		return this.getXmlColumn() != null;
154
	}
154
	}
155
156
	// ********** completion proposals **********
157
158
	@Override
159
	public Iterable<String> getXmlCompletionProposals(int pos) {
160
		Iterable<String> result = super.getXmlCompletionProposals(pos);
161
		if (result != null) {
162
			return result;
163
		}
164
		result = this.column.getXmlCompletionProposals(pos);
165
		if (result != null) {
166
			return result;
167
		}
168
		return null;
169
	}
155
}
170
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmGeneratedValue.java (-1 / +23 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2007, 2012 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 189-192 Link Here
189
	public TextRange getGeneratorTextRange() {
189
	public TextRange getGeneratorTextRange() {
190
		return this.getValidationTextRange(this.xmlGeneratedValue.getGeneratorTextRange());
190
		return this.getValidationTextRange(this.xmlGeneratedValue.getGeneratorTextRange());
191
	}
191
	}
192
193
	// ********** completion proposals **********
194
195
	@Override
196
	public Iterable<String> getXmlCompletionProposals(int pos) {
197
		Iterable<String> result = super.getXmlCompletionProposals(pos);
198
		if (result != null) {
199
			return result;
200
		}
201
		if (this.generatorTouches(pos)) {
202
			return this.getCandidateGeneratorNames();
203
		}
204
		return null;
205
	}
206
207
	protected boolean generatorTouches(int pos) {
208
		return this.xmlGeneratedValue.generatorTouches(pos);
209
	}
210
211
	protected Iterable<String> getCandidateGeneratorNames() {
212
		return this.getPersistenceUnit().getUniqueGeneratorNames();
213
	}
192
}
214
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmGeneratorContainer.java (-1 / +23 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2009, 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2009, 2012 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 212-217 Link Here
212
		return (textRange != null) ? textRange : this.getParent().getValidationTextRange();
212
		return (textRange != null) ? textRange : this.getParent().getValidationTextRange();
213
	}
213
	}
214
214
215
	// ********** completion proposals **********
216
217
	@Override
218
	public Iterable<String> getXmlCompletionProposals(int pos) {
219
		Iterable<String> result = super.getXmlCompletionProposals(pos);
220
		if (result != null) {
221
			return result;
222
		}
223
		if (this.tableGenerator != null) {
224
			result = this.tableGenerator.getXmlCompletionProposals(pos);
225
			if (result != null) {
226
				return result;
227
			}
228
		}
229
		if (this.sequenceGenerator != null) {
230
			result = this.sequenceGenerator.getXmlCompletionProposals(pos);
231
			if (result != null) {
232
				return result;
233
			}
234
		}
235
		return null;
236
	}
215
237
216
	// ********** misc **********
238
	// ********** misc **********
217
239
(-)src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmJoinColumn.java (+25 lines)
Lines 10-15 Link Here
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 org.eclipse.jpt.common.core.utility.TextRange;
12
import org.eclipse.jpt.common.core.utility.TextRange;
13
import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable;
13
import org.eclipse.jpt.jpa.core.context.ReadOnlyJoinColumn;
14
import org.eclipse.jpt.jpa.core.context.ReadOnlyJoinColumn;
14
import org.eclipse.jpt.jpa.core.context.XmlContextNode;
15
import org.eclipse.jpt.jpa.core.context.XmlContextNode;
15
import org.eclipse.jpt.jpa.core.context.orm.OrmJoinColumn;
16
import org.eclipse.jpt.jpa.core.context.orm.OrmJoinColumn;
Lines 173-176 Link Here
173
	protected NamedColumnTextRangeResolver buildTextRangeResolver() {
174
	protected NamedColumnTextRangeResolver buildTextRangeResolver() {
174
		return new OrmJoinColumnTextRangeResolver(this);
175
		return new OrmJoinColumnTextRangeResolver(this);
175
	}
176
	}
177
178
	// ********** completion proposals **********
179
180
	@Override
181
	protected Iterable<String> getConnectedXmlCompletionProposals(int pos) {
182
		Iterable<String> result = super.getConnectedXmlCompletionProposals(pos);
183
		if (result != null) {
184
			return result;
185
		}
186
		if (this.referencedColumnNameTouches(pos)) {
187
			return this.getCandidateReferencedColumnNames();
188
		}
189
		return null;
190
	}
191
192
	protected boolean referencedColumnNameTouches(int pos) {
193
		XmlJoinColumn joinColumn = this.getXmlColumn();
194
		return (joinColumn != null) && (joinColumn.referencedColumnNameTouches(pos));
195
	}
196
197
	protected Iterable<String> getCandidateReferencedColumnNames() {
198
		Table table = this.owner.getReferencedColumnDbTable();
199
		return (table != null) ? table.getSortedColumnIdentifiers() : EmptyIterable.<String> instance();
200
	}
176
}
201
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmJoinTable.java (+16 lines)
Lines 307-312 Link Here
307
		return this.getRelationshipStrategy().validatesAgainstDatabase();
307
		return this.getRelationshipStrategy().validatesAgainstDatabase();
308
	}
308
	}
309
309
310
	// ********** completion proposals **********
311
312
	@Override
313
	public Iterable<String> getXmlCompletionProposals(int pos) {
314
		Iterable<String> result = super.getXmlCompletionProposals(pos);
315
		if (result != null) {
316
			return result;
317
		}
318
		for (OrmJoinColumn column : this.getInverseJoinColumns()) {
319
			result = column.getXmlCompletionProposals(pos);
320
			if (result != null) {
321
				return result;
322
			}
323
		}
324
		return null;
325
	}
310
326
311
	// ********** join column owners **********
327
	// ********** join column owners **********
312
328
(-)src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmOrderable.java (-1 / +15 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2007, 2012 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 400-406 Link Here
400
		}
400
		}
401
	}
401
	}
402
402
403
	// ********** completion proposals **********
403
404
405
	@Override
406
	public Iterable<String> getXmlCompletionProposals(int pos) {
407
		Iterable<String> result = super.getXmlCompletionProposals(pos);
408
		if (result != null) {
409
			return result;
410
		}
411
		result = this.orderColumn.getXmlCompletionProposals(pos);
412
		if (result != null) {
413
			return result;
414
		}
415
		return null;
416
	}
417
	
404
	// ********** order column owner (JPA 2.0) **********
418
	// ********** order column owner (JPA 2.0) **********
405
419
406
	protected class OrderColumnOwner
420
	protected class OrderColumnOwner
(-)src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmOverrideRelationship.java (-3 / +18 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2009, 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2009, 2012 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-27 Link Here
15
import org.eclipse.jpt.jpa.core.context.MappedByRelationship;
15
import org.eclipse.jpt.jpa.core.context.MappedByRelationship;
16
import org.eclipse.jpt.jpa.core.context.OverrideRelationship;
16
import org.eclipse.jpt.jpa.core.context.OverrideRelationship;
17
import org.eclipse.jpt.jpa.core.context.ReadOnlyBaseColumn;
17
import org.eclipse.jpt.jpa.core.context.ReadOnlyBaseColumn;
18
import org.eclipse.jpt.jpa.core.context.ReadOnlyTableColumn.Owner;
19
import org.eclipse.jpt.jpa.core.context.ReadOnlyJoinColumn;
18
import org.eclipse.jpt.jpa.core.context.ReadOnlyJoinColumn;
20
import org.eclipse.jpt.jpa.core.context.ReadOnlyJoinColumnRelationship;
19
import org.eclipse.jpt.jpa.core.context.ReadOnlyJoinColumnRelationship;
21
import org.eclipse.jpt.jpa.core.context.ReadOnlyJoinTable;
20
import org.eclipse.jpt.jpa.core.context.ReadOnlyJoinTable;
22
import org.eclipse.jpt.jpa.core.context.ReadOnlyJoinTableRelationship;
21
import org.eclipse.jpt.jpa.core.context.ReadOnlyJoinTableRelationship;
23
import org.eclipse.jpt.jpa.core.context.ReadOnlyOverrideRelationship;
22
import org.eclipse.jpt.jpa.core.context.ReadOnlyOverrideRelationship;
24
import org.eclipse.jpt.jpa.core.context.ReadOnlyRelationship;
23
import org.eclipse.jpt.jpa.core.context.ReadOnlyRelationship;
24
import org.eclipse.jpt.jpa.core.context.ReadOnlyTableColumn.Owner;
25
import org.eclipse.jpt.jpa.core.context.Relationship;
25
import org.eclipse.jpt.jpa.core.context.Relationship;
26
import org.eclipse.jpt.jpa.core.context.RelationshipMapping;
26
import org.eclipse.jpt.jpa.core.context.RelationshipMapping;
27
import org.eclipse.jpt.jpa.core.context.TypeMapping;
27
import org.eclipse.jpt.jpa.core.context.TypeMapping;
Lines 29-37 Link Here
29
import org.eclipse.jpt.jpa.core.context.orm.OrmJoinColumnRelationshipStrategy;
29
import org.eclipse.jpt.jpa.core.context.orm.OrmJoinColumnRelationshipStrategy;
30
import org.eclipse.jpt.jpa.core.context.orm.OrmJoinTableRelationshipStrategy;
30
import org.eclipse.jpt.jpa.core.context.orm.OrmJoinTableRelationshipStrategy;
31
import org.eclipse.jpt.jpa.core.context.orm.OrmRelationshipStrategy;
31
import org.eclipse.jpt.jpa.core.context.orm.OrmRelationshipStrategy;
32
import org.eclipse.jpt.jpa.core.internal.context.TableColumnTextRangeResolver;
33
import org.eclipse.jpt.jpa.core.internal.context.JoinColumnTextRangeResolver;
32
import org.eclipse.jpt.jpa.core.internal.context.JoinColumnTextRangeResolver;
34
import org.eclipse.jpt.jpa.core.internal.context.JptValidator;
33
import org.eclipse.jpt.jpa.core.internal.context.JptValidator;
34
import org.eclipse.jpt.jpa.core.internal.context.TableColumnTextRangeResolver;
35
import org.eclipse.jpt.jpa.core.internal.context.TableTextRangeResolver;
35
import org.eclipse.jpt.jpa.core.internal.context.TableTextRangeResolver;
36
import org.eclipse.jpt.jpa.core.internal.context.orm.AbstractOrmXmlContextNode;
36
import org.eclipse.jpt.jpa.core.internal.context.orm.AbstractOrmXmlContextNode;
37
import org.eclipse.jpt.jpa.core.internal.context.orm.GenericOrmOverrideJoinColumnRelationshipStrategy;
37
import org.eclipse.jpt.jpa.core.internal.context.orm.GenericOrmOverrideJoinColumnRelationshipStrategy;
Lines 305-308 Link Here
305
	public JptValidator buildJoinTableInverseJoinColumnValidator(ReadOnlyJoinColumn column, ReadOnlyJoinColumn.Owner owner, JoinColumnTextRangeResolver textRangeResolver) {
305
	public JptValidator buildJoinTableInverseJoinColumnValidator(ReadOnlyJoinColumn column, ReadOnlyJoinColumn.Owner owner, JoinColumnTextRangeResolver textRangeResolver) {
306
		return this.getAssociationOverride2_0().buildJoinTableInverseJoinColumnValidator(column, owner, textRangeResolver);
306
		return this.getAssociationOverride2_0().buildJoinTableInverseJoinColumnValidator(column, owner, textRangeResolver);
307
	}
307
	}
308
309
	// ********** completion proposals **********
310
311
	@Override
312
	public Iterable<String> getXmlCompletionProposals(int pos) {
313
		Iterable<String> result = super.getXmlCompletionProposals(pos);
314
		if (result != null) {
315
			return result;
316
		}
317
		result = this.strategy.getXmlCompletionProposals(pos);
318
		if (result != null) {
319
			return result;
320
		}
321
		return null;
322
	}
308
}
323
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmPrimaryKeyJoinColumn.java (+25 lines)
Lines 10-15 Link Here
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 org.eclipse.jpt.common.core.utility.TextRange;
12
import org.eclipse.jpt.common.core.utility.TextRange;
13
import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable;
13
import org.eclipse.jpt.jpa.core.context.ReadOnlyPrimaryKeyJoinColumn;
14
import org.eclipse.jpt.jpa.core.context.ReadOnlyPrimaryKeyJoinColumn;
14
import org.eclipse.jpt.jpa.core.context.XmlContextNode;
15
import org.eclipse.jpt.jpa.core.context.XmlContextNode;
15
import org.eclipse.jpt.jpa.core.context.orm.OrmPrimaryKeyJoinColumn;
16
import org.eclipse.jpt.jpa.core.context.orm.OrmPrimaryKeyJoinColumn;
Lines 169-172 Link Here
169
	public TextRange getReferencedColumnNameTextRange() {
170
	public TextRange getReferencedColumnNameTextRange() {
170
		return this.getValidationTextRange(this.xmlColumn.getReferencedColumnNameTextRange());
171
		return this.getValidationTextRange(this.xmlColumn.getReferencedColumnNameTextRange());
171
	}
172
	}
173
174
	// ********** completion proposals **********
175
176
	@Override
177
	protected Iterable<String> getConnectedXmlCompletionProposals(int pos) {
178
		Iterable<String> result = super.getConnectedXmlCompletionProposals(pos);
179
		if (result != null) {
180
			return result;
181
		}
182
		if (this.referencedColumnNameTouches(pos)) {
183
			return this.getCandidateReferencedColumnNames();
184
		}
185
		return null;
186
	}
187
188
	public boolean referencedColumnNameTouches(int pos) {
189
		XmlPrimaryKeyJoinColumn column = this.getXmlColumn();
190
		return (column != null) && (column.referencedColumnNameTouches(pos));
191
	}
192
193
	protected Iterable<String> getCandidateReferencedColumnNames() {
194
		Table table = this.owner.getReferencedColumnDbTable();
195
		return (table != null) ? table.getSortedColumnIdentifiers() : EmptyIterable.<String> instance();
196
	}
172
}
197
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmReferenceTable.java (-1 / +18 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2007, 2012 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 261-264 Link Here
261
	protected void validateJoinColumns(List<IMessage> messages, IReporter reporter) {
261
	protected void validateJoinColumns(List<IMessage> messages, IReporter reporter) {
262
		this.validateNodes(this.getJoinColumns(), messages, reporter);
262
		this.validateNodes(this.getJoinColumns(), messages, reporter);
263
	}
263
	}
264
265
	// ********** completion proposals **********
266
267
	@Override
268
	public Iterable<String> getXmlCompletionProposals(int pos) {
269
		Iterable<String> result = super.getXmlCompletionProposals(pos);
270
		if (result != null) {
271
			return result;
272
		}
273
		for (OrmJoinColumn column : this.getJoinColumns()) {
274
			result = column.getXmlCompletionProposals(pos);
275
			if (result != null) {
276
				return result;
277
			}
278
		}
279
		return null;
280
	}
264
}
281
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmSecondaryTable.java (+16 lines)
Lines 317-322 Link Here
317
		}
317
		}
318
	}
318
	}
319
319
320
	// ********** completion proposals **********
321
322
	@Override
323
	public Iterable<String> getXmlCompletionProposals(int pos) {
324
		Iterable<String> result = super.getXmlCompletionProposals(pos);
325
		if (result != null) {
326
			return result;
327
		}
328
		for (OrmPrimaryKeyJoinColumn column : this.getPrimaryKeyJoinColumns()) {
329
			result = column.getXmlCompletionProposals(pos);
330
			if (result != null) {
331
				return result;
332
			}
333
		}
334
		return null;
335
	}
320
336
321
	// ********** primary key join column owner adapter **********
337
	// ********** primary key join column owner adapter **********
322
338
(-)src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmTableGenerator.java (-1 / +68 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2007, 2012 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 450-453 Link Here
450
		}
450
		}
451
		return isIdentical;
451
		return isIdentical;
452
	}
452
	}
453
454
	// ********** completion proposals **********
455
456
	@Override
457
	public Iterable<String> getXmlCompletionProposals(int pos) {
458
		Iterable<String> result = super.getXmlCompletionProposals(pos);
459
		if (result != null) {
460
			return result;
461
		}
462
		for (OrmUniqueConstraint constraint : this.getUniqueConstraints()) {
463
			result = constraint.getXmlCompletionProposals(pos);
464
			if (result != null) {
465
				return result;
466
			}
467
		}
468
		return null;
469
	}
470
471
	/**
472
	 * called if the database is connected:
473
	 * table, schema, catalog, pkColumnName, valueColumnName
474
	 */
475
	@Override
476
	protected Iterable<String> getConnectedXmlCompletionProposals(int pos) {
477
		Iterable<String> result = super.getConnectedXmlCompletionProposals(pos);
478
		if (result != null) {
479
			return result;
480
		}
481
		if (this.tableTouches(pos)) {
482
			return this.getCandidateTables();
483
		}
484
		if (this.pkColumnNameTouches(pos)) {
485
			return this.getCandidateColumnNames();
486
		}
487
		if (this.valueColumnNameTouches(pos)) {
488
			return this.getCandidateColumnNames();
489
		}
490
		return null;
491
	}
492
493
	// ********** content assist: table
494
495
	protected boolean tableTouches(int pos) {
496
		return this.xmlGenerator.tableTouches(pos);
497
	}
498
499
	protected Iterable<String> getCandidateTables() {
500
		Schema dbSchema = this.getDbSchema();
501
		return (dbSchema != null) ? dbSchema.getSortedTableIdentifiers() : EmptyIterable.<String> instance();
502
	}
503
	
504
	// ********** content assist: pkColumnName
505
506
	protected boolean pkColumnNameTouches(int pos) {
507
		return this.xmlGenerator.pkColumnNameTouches(pos);
508
	}
509
510
	protected Iterable<String> getCandidateColumnNames() {
511
		Table table = this.getDbTable();
512
		return (table != null) ? table.getSortedColumnIdentifiers() : EmptyIterable.<String> instance();
513
	}
514
515
	// ********** content assist: valueColumnName
516
517
	protected boolean valueColumnNameTouches(int pos) {
518
		return this.xmlGenerator.valueColumnNameTouches(pos);
519
	}
453
}
520
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmUniqueConstraint.java (-1 / +23 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2008, 2012 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 105-110 Link Here
105
		return isIdentical;
105
		return isIdentical;
106
	}
106
	}
107
107
108
	// ********** completion proposals **********
109
110
	@Override
111
	protected Iterable<String> getConnectedXmlCompletionProposals(int pos) {
112
		Iterable<String> result = super.getConnectedXmlCompletionProposals(pos);
113
		if (result != null) {
114
			return result;
115
		}
116
		if (this.columnNamesTouches(pos)) {
117
			return this.getCandidateColumnNames();
118
		}
119
		return null;
120
	}
121
122
	protected boolean columnNamesTouches(int pos) {
123
		return this.xmlUniqueConstraint.columnNamesTouches(pos);
124
	}
125
126
	protected Iterable<String> getCandidateColumnNames() {
127
		return this.owner.getCandidateUniqueConstraintColumnNames();
128
	}
129
108
	// ********** misc **********
130
	// ********** misc **********
109
131
110
	@Override
132
	@Override
(-)src/org/eclipse/jpt/jpa/core/internal/jpa2/context/orm/AbstractOrmElementCollectionMapping2_0.java (+59 lines)
Lines 1743-1748 Link Here
1743
		}
1743
		}
1744
	}
1744
	}
1745
1745
1746
	// ********** completion proposals **********
1747
	
1748
	@Override
1749
	public Iterable<String> getXmlCompletionProposals(int pos) {
1750
		Iterable<String> result = super.getXmlCompletionProposals(pos);
1751
		if (result != null) {
1752
			return result;
1753
		}
1754
		result = this.collectionTable.getXmlCompletionProposals(pos);
1755
		if (result != null) {
1756
			return result;
1757
		}
1758
		result = this.valueColumn.getXmlCompletionProposals(pos);
1759
		if (result != null) {
1760
			return result;
1761
		}
1762
		result = this.converter.getXmlCompletionProposals(pos);
1763
		if (result != null) {
1764
			return result;
1765
		}
1766
		result = this.orderable.getXmlCompletionProposals(pos);
1767
		if (result != null) {
1768
			return result;
1769
		}
1770
		result = this.valueAttributeOverrideContainer.getXmlCompletionProposals(pos);
1771
		if (result != null) {
1772
			return result;
1773
		}
1774
		result = this.valueAssociationOverrideContainer.getXmlCompletionProposals(pos);
1775
		if (result != null) {
1776
			return result;
1777
		}
1778
		if (this.mapKeyNameTouches(pos)) {
1779
			return this.getCandidateMapKeyNames();
1780
		}
1781
		result = this.mapKeyColumn.getXmlCompletionProposals(pos);
1782
		if (result != null) {
1783
			return result;
1784
		}
1785
		result = this.mapKeyConverter.getXmlCompletionProposals(pos);
1786
		if (result != null) {
1787
			return result;
1788
		}
1789
		result = this.mapKeyAttributeOverrideContainer.getXmlCompletionProposals(pos);
1790
		if (result != null) {
1791
			return result;
1792
		}
1793
		for (OrmJoinColumn joinColumn : this.getMapKeyJoinColumns()) {
1794
			result = joinColumn.getXmlCompletionProposals(pos);
1795
			if (result != null) {
1796
				return result;
1797
			}
1798
		}
1799
		return null;
1800
	}
1801
	
1802
	protected boolean mapKeyNameTouches(int pos) {
1803
		return this.xmlAttributeMapping.mapKeyNameTouches(pos);
1804
	}
1746
1805
1747
	// ********** abstract owner **********
1806
	// ********** abstract owner **********
1748
1807
(-)src/org/eclipse/jpt/jpa/core/internal/jpa2/context/orm/GenericOrmDerivedIdentity2_0.java (-1 / +18 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2009, 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2009, 2012 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 170-173 Link Here
170
	public TextRange getValidationTextRange() {
170
	public TextRange getValidationTextRange() {
171
		return this.getMapping().getValidationTextRange();
171
		return this.getMapping().getValidationTextRange();
172
	}
172
	}
173
174
	// ************** completion proposals **********
175
176
	@Override
177
	public Iterable<String> getXmlCompletionProposals(int pos) {
178
		Iterable<String> result = super.getXmlCompletionProposals(pos);
179
		if (result != null) {
180
			return result;
181
		}
182
		if (this.strategy != null) {
183
			result = ((XmlContextNode) this.strategy).getXmlCompletionProposals(pos);
184
			if (result != null) {
185
				return result;
186
			}
187
		}
188
		return null;
189
	}
173
}
190
}
(-)src/org/eclipse/jpt/jpa/core/resource/orm/AbstractXmlAttributeMapping.java (+11 lines)
Lines 279-282 Link Here
279
	protected static Translator buildAccessTranslator() {
279
	protected static Translator buildAccessTranslator() {
280
		return new Translator(JPA.ACCESS, OrmPackage.eINSTANCE.getXmlAccessHolder_Access(), Translator.DOM_ATTRIBUTE);
280
		return new Translator(JPA.ACCESS, OrmPackage.eINSTANCE.getXmlAccessHolder_Access(), Translator.DOM_ATTRIBUTE);
281
	}
281
	}
282
283
	// *********** content assist ************
284
	
285
	protected TextRange getNameCodeAssistTextRange() {
286
		return getAttributeCodeAssistTextRange(JPA.NAME);
287
	}
288
289
	public boolean nameTouches(int pos) {
290
		TextRange textRange = this.getNameCodeAssistTextRange();
291
		return (textRange != null) && (textRange.touches(pos));
292
	}
282
}
293
}
(-)src/org/eclipse/jpt/jpa/core/resource/orm/AbstractXmlBaseColumn.java (-1 / +12 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2008, 2012 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 533-536 Link Here
533
		return new Translator(JPA.TABLE, OrmPackage.eINSTANCE.getXmlBaseColumn_Table(), Translator.DOM_ATTRIBUTE);
533
		return new Translator(JPA.TABLE, OrmPackage.eINSTANCE.getXmlBaseColumn_Table(), Translator.DOM_ATTRIBUTE);
534
	}
534
	}
535
	
535
	
536
	// ************ content assist ************
537
	
538
	private TextRange getTableCodeAssistTextRange() {
539
		return getAttributeCodeAssistTextRange(JPA.TABLE);
540
	}
541
	
542
	public boolean tableTouches(int pos) {
543
		TextRange textRange = this.getTableCodeAssistTextRange();
544
		return (textRange != null) && (textRange.touches(pos));
545
	}
546
	
536
} // AbstractXmlAbstractColumn
547
} // AbstractXmlAbstractColumn
(-)src/org/eclipse/jpt/jpa/core/resource/orm/AbstractXmlMultiRelationshipMapping.java (-1 / +21 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2007, 2012 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 1123-1126 Link Here
1123
	protected static Translator buildOrderColumnTranslator() {
1123
	protected static Translator buildOrderColumnTranslator() {
1124
		return XmlOrderColumn.buildTranslator(JPA2_0.ORDER_COLUMN, OrmV2_0Package.eINSTANCE.getXmlOrderable_2_0_OrderColumn());
1124
		return XmlOrderColumn.buildTranslator(JPA2_0.ORDER_COLUMN, OrmV2_0Package.eINSTANCE.getXmlOrderable_2_0_OrderColumn());
1125
	}
1125
	}
1126
1127
	// ********** content assist ***************
1128
	
1129
	public TextRange getMappedByCodeAssistTextRange() {
1130
		return getAttributeCodeAssistTextRange(JPA.MAPPED_BY);
1131
	}
1132
	
1133
	public TextRange getMapKeyNameCodeAssistTextRange() {
1134
		return getAttributeCodeAssistTextRange(JPA.MAP_KEY);
1135
	}
1136
	
1137
	public boolean mappedByTouches(int pos) {
1138
		TextRange textRange = this.getMappedByCodeAssistTextRange();
1139
		return (textRange!= null) && textRange.touches(pos);
1140
	}
1141
	
1142
	public boolean mapKeyNameTouches(int pos) {
1143
		TextRange textRange = this.getMapKeyNameCodeAssistTextRange();
1144
		return (textRange != null) && textRange.touches(pos);
1145
	}
1126
}
1146
}
(-)src/org/eclipse/jpt/jpa/core/resource/orm/AbstractXmlNamedColumn.java (-1 / +12 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2008, 2012 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 274-277 Link Here
274
		return new Translator(JPA.COLUMN_DEFINITION, OrmPackage.eINSTANCE.getXmlNamedColumn_ColumnDefinition(), Translator.DOM_ATTRIBUTE);
274
		return new Translator(JPA.COLUMN_DEFINITION, OrmPackage.eINSTANCE.getXmlNamedColumn_ColumnDefinition(), Translator.DOM_ATTRIBUTE);
275
	}
275
	}
276
276
277
	// *********** content assist ***********
278
	
279
	public TextRange getColumnNameCodeAssistTextRange() {
280
		return getAttributeCodeAssistTextRange(JPA.NAME);
281
	}
282
	
283
	public boolean columnNameTouches(int pos) {
284
		TextRange textRange = this.getColumnNameCodeAssistTextRange();
285
		return (textRange != null) && (textRange.touches(pos));
286
	}
287
277
} // AbstractXmlNamedColumn
288
} // AbstractXmlNamedColumn
(-)src/org/eclipse/jpt/jpa/core/resource/orm/AbstractXmlTable.java (-1 / +29 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2009 Oracle. All rights reserved.
2
 * Copyright (c) 2008, 2012 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 436-439 Link Here
436
		return XmlUniqueConstraint.buildTranslator(JPA.UNIQUE_CONSTRAINT, OrmPackage.eINSTANCE.getAbstractXmlTable_UniqueConstraints());
436
		return XmlUniqueConstraint.buildTranslator(JPA.UNIQUE_CONSTRAINT, OrmPackage.eINSTANCE.getAbstractXmlTable_UniqueConstraints());
437
	}
437
	}
438
438
439
	//***************** content assist ****************
440
	
441
	public TextRange getNameCodeAssistTextRange() {
442
		return getAttributeCodeAssistTextRange(JPA.NAME);
443
	}
444
	
445
	public TextRange getSchemaCodeAssistTextRange() {
446
		return getAttributeCodeAssistTextRange(JPA.SCHEMA);
447
	}
448
		
449
	public TextRange getCatalogCodeAssistTextRange() {
450
		return getAttributeCodeAssistTextRange(JPA.CATALOG);
451
	}
452
	
453
	public boolean nameTouches(int pos) {
454
		TextRange textRange = this.getNameCodeAssistTextRange();
455
		return (textRange != null) && (textRange.touches(pos));
456
	}
457
	
458
	public boolean schemaTouches(int pos) {
459
		TextRange textRange = this.getSchemaCodeAssistTextRange();
460
		return (textRange != null) && (textRange.touches(pos));
461
	}
462
	
463
	public boolean catalogTouches(int pos) {
464
		TextRange textRange = this.getCatalogCodeAssistTextRange();
465
		return (textRange != null) && (textRange.touches(pos));
466
	}
439
} // AbstractXmlBaseTable
467
} // AbstractXmlBaseTable
(-)src/org/eclipse/jpt/jpa/core/resource/orm/AbstractXmlTypeMapping.java (+10 lines)
Lines 550-553 Link Here
550
		return new ReplaceEdit(offset, packageLength, newName);
550
		return new ReplaceEdit(offset, packageLength, newName);
551
	}
551
	}
552
552
553
	// *********** content assist ************
554
	
555
	protected TextRange getClassNameCodeAssistTextRange() {
556
		return getAttributeCodeAssistTextRange(JPA.CLASS);
557
	}
558
559
	public boolean classNameTouches(int pos) {
560
		TextRange textRange = this.getClassNameCodeAssistTextRange();
561
		return (textRange != null) && (textRange.touches(pos));
562
	}
553
} // TypeMapping
563
} // TypeMapping
(-)src/org/eclipse/jpt/jpa/core/resource/orm/XmlAssociationOverride.java (-1 / +11 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2010 Oracle. All rights reserved.
2
 * Copyright (c) 2007, 2012 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 518-521 Link Here
518
	protected static Translator buildJoinTableTranslator() {
518
	protected static Translator buildJoinTableTranslator() {
519
		return XmlJoinTable.buildTranslator(JPA.JOIN_TABLE, OrmPackage.eINSTANCE.getXmlJoinTableContainer_JoinTable());
519
		return XmlJoinTable.buildTranslator(JPA.JOIN_TABLE, OrmPackage.eINSTANCE.getXmlJoinTableContainer_JoinTable());
520
	}
520
	}
521
522
	// ************ content assist ***********
523
	public TextRange getNameTextCodeAssistRange() {
524
		return getAttributeCodeAssistTextRange(JPA.NAME);
525
	}
526
	
527
	public boolean nameTouches(int pos) {
528
		TextRange textRange = this.getNameTextCodeAssistRange();
529
		return (textRange != null) && (textRange.touches(pos));
530
	}
521
}
531
}
(-)src/org/eclipse/jpt/jpa/core/resource/orm/XmlAttributeMapping.java (-1 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2009 Oracle. All rights reserved.
2
 * Copyright (c) 2007, 2012 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 67-70 Link Here
67
	//TODO unsure about this api, might change soon
67
	//TODO unsure about this api, might change soon
68
	String getMappingKey();
68
	String getMappingKey();
69
69
70
	boolean nameTouches(int pos);
70
} // XmlAttributeMapping
71
} // XmlAttributeMapping
(-)src/org/eclipse/jpt/jpa/core/resource/orm/XmlAttributeOverride.java (-1 / +12 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2010 Oracle. All rights reserved.
2
 * Copyright (c) 2007, 2012 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 437-440 Link Here
437
	protected static Translator buildColumnTranslator() {
437
	protected static Translator buildColumnTranslator() {
438
		return XmlColumn.buildTranslator(JPA.COLUMN, OrmPackage.eINSTANCE.getXmlAttributeOverride_Column());
438
		return XmlColumn.buildTranslator(JPA.COLUMN, OrmPackage.eINSTANCE.getXmlAttributeOverride_Column());
439
	}
439
	}
440
441
	// ************* content assist ************
442
	
443
	public TextRange getNameCodeAssistTextRange() {
444
		return getAttributeCodeAssistTextRange(JPA.NAME);
445
	}
446
	
447
	public boolean nameTouches(int pos) {
448
		TextRange textRange = this.getNameTextRange();
449
		return (textRange != null) && (textRange.touches(pos));
450
	}
440
}
451
}
(-)src/org/eclipse/jpt/jpa/core/resource/orm/XmlBaseColumn.java (-1 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2012 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 172-175 Link Here
172
172
173
	TextRange getTableTextRange();
173
	TextRange getTableTextRange();
174
174
175
	boolean tableTouches(int pos);
176
175
} // XmlBaseColumn
177
} // XmlBaseColumn
(-)src/org/eclipse/jpt/jpa/core/resource/orm/XmlElementCollection.java (-1 / +12 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 *  Copyright (c) 2009, 2011 Oracle. 
2
 *  Copyright (c) 2009, 2012 Oracle. 
3
 *  All rights reserved.  This program and the accompanying materials are 
3
 *  All rights reserved.  This program and the accompanying materials are 
4
 *  made available under the terms of the Eclipse Public License v1.0 which 
4
 *  made available under the terms of the Eclipse Public License v1.0 which 
5
 *  accompanies this distribution, and is available at 
5
 *  accompanies this distribution, and is available at 
Lines 1684-1687 Link Here
1684
		return getMapKeyClass().createRenamePackageEdit(newName);		
1684
		return getMapKeyClass().createRenamePackageEdit(newName);		
1685
	}
1685
	}
1686
1686
1687
	// ********** content assist ***************
1688
	
1689
	public TextRange getMapKeyNameCodeAssistTextRange() {
1690
		return getAttributeCodeAssistTextRange(JPA.MAP_KEY);
1691
	}
1692
	
1693
	public boolean mapKeyNameTouches(int pos) {
1694
		TextRange textRange = this.getMapKeyNameCodeAssistTextRange();
1695
		return (textRange != null) && textRange.touches(pos);
1696
	}
1697
1687
}
1698
}
(-)src/org/eclipse/jpt/jpa/core/resource/orm/XmlEntityMappings.java (+18 lines)
Lines 23-28 Link Here
23
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
23
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
24
import org.eclipse.emf.ecore.util.InternalEList;
24
import org.eclipse.emf.ecore.util.InternalEList;
25
import org.eclipse.jpt.common.core.internal.utility.translators.SimpleRootTranslator;
25
import org.eclipse.jpt.common.core.internal.utility.translators.SimpleRootTranslator;
26
import org.eclipse.jpt.common.core.utility.TextRange;
26
import org.eclipse.jpt.common.utility.internal.CollectionTools;
27
import org.eclipse.jpt.common.utility.internal.CollectionTools;
27
import org.eclipse.jpt.jpa.core.resource.orm.v2_0.JPA2_0;
28
import org.eclipse.jpt.jpa.core.resource.orm.v2_0.JPA2_0;
28
import org.eclipse.jpt.jpa.core.resource.xml.AbstractJpaRootEObject;
29
import org.eclipse.jpt.jpa.core.resource.xml.AbstractJpaRootEObject;
Lines 1116-1119 Link Here
1116
		return new ReplaceEdit(offset, this.package_.length(), newName);		
1117
		return new ReplaceEdit(offset, this.package_.length(), newName);		
1117
	}
1118
	}
1118
1119
1120
	// *********** content assist *********
1121
	
1122
	public boolean schemaTouches(int pos) {
1123
		TextRange textRange = this.getElementCodeAssistTextRange(JPA.SCHEMA);
1124
		return (textRange != null) && (textRange.touches(pos));
1125
	}
1126
1127
	public boolean catalogTouches(int pos) {
1128
		TextRange textRange = this.getElementCodeAssistTextRange(JPA.CATALOG);
1129
		return (textRange != null) && (textRange.touches(pos));
1130
	}
1131
1132
	public boolean packageTouches(int pos) {
1133
		TextRange textRange = this.getElementCodeAssistTextRange(JPA.PACKAGE);
1134
		return (textRange != null) && (textRange.touches(pos));
1135
	}
1136
1119
}
1137
}
(-)src/org/eclipse/jpt/jpa/core/resource/orm/XmlGeneratedValue.java (-1 / +11 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2009 Oracle. All rights reserved.
2
 * Copyright (c) 2007, 2012 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 300-303 Link Here
300
	protected static Translator buildGeneratorTranslator() {
300
	protected static Translator buildGeneratorTranslator() {
301
		return new Translator(JPA.GENERATOR, OrmPackage.eINSTANCE.getXmlGeneratedValue_Generator(), Translator.DOM_ATTRIBUTE);
301
		return new Translator(JPA.GENERATOR, OrmPackage.eINSTANCE.getXmlGeneratedValue_Generator(), Translator.DOM_ATTRIBUTE);
302
	}
302
	}
303
304
	// *********** content assist ************
305
	
306
	protected TextRange getGeneratorCodeAssistTextRange() {
307
		return getAttributeCodeAssistTextRange(JPA.GENERATOR);
308
	}
309
	public boolean generatorTouches(int pos) {
310
		TextRange textRange = this.getGeneratorCodeAssistTextRange();
311
		return (textRange != null) && (textRange.touches(pos));
312
	}
303
} // GeneratedValue
313
} // GeneratedValue
(-)src/org/eclipse/jpt/jpa/core/resource/orm/XmlGenerator.java (-2 / +10 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2009 Oracle. All rights reserved.
2
 * Copyright (c) 2007, 2012 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 116-120 Link Here
116
	 */
116
	 */
117
	void setAllocationSize(Integer value);
117
	void setAllocationSize(Integer value);
118
	
118
	
119
	public TextRange getNameTextRange();
119
	TextRange getNameTextRange();
120
	
121
	TextRange getSchemaCodeAssistTextRange();
122
	
123
	TextRange getCatalogCodeAssistTextRange();
124
	
125
	boolean schemaTouches(int pos);
126
	
127
	boolean catalogTouches(int pos);
120
}
128
}
(-)src/org/eclipse/jpt/jpa/core/resource/orm/XmlJoinColumn.java (-1 / +12 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2007, 2012 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 263-266 Link Here
263
	protected static Translator buildReferencedColumnNameTranslator() {
263
	protected static Translator buildReferencedColumnNameTranslator() {
264
		return new Translator(JPA.REFERENCED_COLUMN_NAME, OrmPackage.eINSTANCE.getXmlBaseJoinColumn_ReferencedColumnName(), Translator.DOM_ATTRIBUTE);
264
		return new Translator(JPA.REFERENCED_COLUMN_NAME, OrmPackage.eINSTANCE.getXmlBaseJoinColumn_ReferencedColumnName(), Translator.DOM_ATTRIBUTE);
265
	}
265
	}
266
267
	// ************ content assist **************
268
	
269
	public TextRange getReferencedColumnNameCodeAssistTextRange() {
270
		return getAttributeCodeAssistTextRange(JPA.REFERENCED_COLUMN_NAME);
271
	}
272
273
	public boolean referencedColumnNameTouches(int pos) {
274
		TextRange textRange = this.getReferencedColumnNameCodeAssistTextRange();
275
		return (textRange != null) && (textRange.touches(pos));
276
	}
266
} // JoinColumn
277
} // JoinColumn
(-)src/org/eclipse/jpt/jpa/core/resource/orm/XmlMappedByMapping.java (-2 / +4 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 *  Copyright (c) 2009  Oracle. 
2
 *  Copyright (c) 2012  Oracle. 
3
 *  All rights reserved.  This program and the accompanying materials are 
3
 *  All rights reserved.  This program and the accompanying materials are 
4
 *  made available under the terms of the Eclipse Public License v1.0 which 
4
 *  made available under the terms of the Eclipse Public License v1.0 which 
5
 *  accompanies this distribution, and is available at 
5
 *  accompanies this distribution, and is available at 
Lines 64-68 Link Here
64
	 */
64
	 */
65
	void setMappedBy(String value);
65
	void setMappedBy(String value);
66
66
67
	TextRange getMappedByTextRange();	
67
	TextRange getMappedByTextRange();
68
69
	boolean mappedByTouches(int pos);
68
}
70
}
(-)src/org/eclipse/jpt/jpa/core/resource/orm/XmlNamedColumn.java (-1 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2012 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 92-95 Link Here
92
92
93
	TextRange getNameTextRange();
93
	TextRange getNameTextRange();
94
94
95
	boolean columnNameTouches(int pos);
96
95
} // XmlNamedColumn
97
} // XmlNamedColumn
(-)src/org/eclipse/jpt/jpa/core/resource/orm/XmlOneToOne.java (-1 / +12 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2010 Oracle. All rights reserved.
2
 * Copyright (c) 2007, 2012 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 464-467 Link Here
464
	protected static Translator buildPrimaryKeyJoinColumnTranslator() {
464
	protected static Translator buildPrimaryKeyJoinColumnTranslator() {
465
		return XmlPrimaryKeyJoinColumn.buildTranslator(JPA.PRIMARY_KEY_JOIN_COLUMN, OrmPackage.eINSTANCE.getXmlPrimaryKeyJoinColumnContainer_PrimaryKeyJoinColumns());
465
		return XmlPrimaryKeyJoinColumn.buildTranslator(JPA.PRIMARY_KEY_JOIN_COLUMN, OrmPackage.eINSTANCE.getXmlPrimaryKeyJoinColumnContainer_PrimaryKeyJoinColumns());
466
	}
466
	}
467
468
	// ********** content assist ***************
469
	
470
	public TextRange getMappedByCodeAssistTextRange() {
471
		return getAttributeCodeAssistTextRange(JPA.MAPPED_BY);
472
	}
473
	
474
	public boolean mappedByTouches(int pos) {
475
		TextRange textRange = this.getMappedByCodeAssistTextRange();
476
		return (textRange!= null) && textRange.touches(pos);
477
	}
467
}
478
}
(-)src/org/eclipse/jpt/jpa/core/resource/orm/XmlOverride.java (-1 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2010 Oracle. All rights reserved.
2
 * Copyright (c) 2012 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 64-67 Link Here
64
	void setName(String value);
64
	void setName(String value);
65
65
66
	TextRange getNameTextRange();
66
	TextRange getNameTextRange();
67
68
	boolean nameTouches(int pos);
67
} // XmlOverride
69
} // XmlOverride
(-)src/org/eclipse/jpt/jpa/core/resource/orm/XmlPersistenceUnitDefaults.java (+13 lines)
Lines 17-22 Link Here
17
import org.eclipse.emf.ecore.impl.ENotificationImpl;
17
import org.eclipse.emf.ecore.impl.ENotificationImpl;
18
import org.eclipse.jpt.common.core.internal.utility.translators.EmptyTagBooleanTranslator;
18
import org.eclipse.jpt.common.core.internal.utility.translators.EmptyTagBooleanTranslator;
19
import org.eclipse.jpt.common.core.internal.utility.translators.SimpleTranslator;
19
import org.eclipse.jpt.common.core.internal.utility.translators.SimpleTranslator;
20
import org.eclipse.jpt.common.core.utility.TextRange;
20
import org.eclipse.jpt.jpa.core.resource.orm.v2_0.JPA2_0;
21
import org.eclipse.jpt.jpa.core.resource.orm.v2_0.JPA2_0;
21
import org.eclipse.jpt.jpa.core.resource.orm.v2_0.OrmV2_0Package;
22
import org.eclipse.jpt.jpa.core.resource.orm.v2_0.OrmV2_0Package;
22
import org.eclipse.jpt.jpa.core.resource.orm.v2_0.XmlPersistenceUnitDefaults_2_0;
23
import org.eclipse.jpt.jpa.core.resource.orm.v2_0.XmlPersistenceUnitDefaults_2_0;
Lines 726-729 Link Here
726
	protected static Translator buildEntityListenersTranslator() {
727
	protected static Translator buildEntityListenersTranslator() {
727
		return EntityListeners.buildTranslator(JPA.ENTITY_LISTENERS, OrmPackage.eINSTANCE.getXmlPersistenceUnitDefaults_EntityListeners());
728
		return EntityListeners.buildTranslator(JPA.ENTITY_LISTENERS, OrmPackage.eINSTANCE.getXmlPersistenceUnitDefaults_EntityListeners());
728
	}
729
	}
730
731
	// *********** content assist *********
732
	
733
	public boolean schemaTouches(int pos) {
734
		TextRange textRange = this.getElementCodeAssistTextRange(JPA.SCHEMA);
735
		return (textRange != null) && (textRange.touches(pos));
736
	}
737
738
	public boolean catalogTouches(int pos) {
739
		TextRange textRange = this.getElementCodeAssistTextRange(JPA.CATALOG);
740
		return (textRange != null) && (textRange.touches(pos));
741
	}
729
}
742
}
(-)src/org/eclipse/jpt/jpa/core/resource/orm/XmlPrimaryKeyJoinColumn.java (-1 / +12 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2007, 2012 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 259-262 Link Here
259
		return new Translator(JPA.REFERENCED_COLUMN_NAME, OrmPackage.eINSTANCE.getXmlBaseJoinColumn_ReferencedColumnName(), Translator.DOM_ATTRIBUTE);
259
		return new Translator(JPA.REFERENCED_COLUMN_NAME, OrmPackage.eINSTANCE.getXmlBaseJoinColumn_ReferencedColumnName(), Translator.DOM_ATTRIBUTE);
260
	}
260
	}
261
	
261
	
262
	// *********** content assist ***********
263
	
264
	public TextRange getReferencedColumnNameCodeAssistTextRange() {
265
		return getAttributeCodeAssistTextRange(JPA.REFERENCED_COLUMN_NAME);
266
	}
267
268
	public boolean referencedColumnNameTouches(int pos) {
269
		TextRange textRange = this.getReferencedColumnNameCodeAssistTextRange();
270
		return (textRange != null) && (textRange.touches(pos));
271
	}
272
	
262
} // XmlPrimaryKeyJoinColumnImpl
273
} // XmlPrimaryKeyJoinColumnImpl
(-)src/org/eclipse/jpt/jpa/core/resource/orm/XmlSequenceGenerator.java (-1 / +30 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2009 Oracle. All rights reserved.
2
 * Copyright (c) 2007, 2012 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 699-702 Link Here
699
	protected static Translator buildSchemaTranslator() {
699
	protected static Translator buildSchemaTranslator() {
700
		return new Translator(JPA.SCHEMA, OrmV2_0Package.eINSTANCE.getXmlSequenceGenerator_2_0_Schema(), Translator.DOM_ATTRIBUTE);
700
		return new Translator(JPA.SCHEMA, OrmV2_0Package.eINSTANCE.getXmlSequenceGenerator_2_0_Schema(), Translator.DOM_ATTRIBUTE);
701
	}
701
	}
702
703
	// *********** content assist ****************
704
	
705
	public TextRange getSequenceNameCodeAssistTextRange() {
706
		return getAttributeCodeAssistTextRange(JPA.SEQUENCE_NAME);
707
	}
708
	
709
	public TextRange getSchemaCodeAssistTextRange() {
710
		return getAttributeCodeAssistTextRange(JPA.SCHEMA);
711
	}
712
	
713
	public TextRange getCatalogCodeAssistTextRange() {
714
		return getAttributeCodeAssistTextRange(JPA.CATALOG);
715
	}
716
	
717
	public boolean sequenceNameTouches(int pos) {
718
		TextRange textRange = this.getSequenceNameCodeAssistTextRange();
719
		return (textRange != null) && (textRange.touches(pos));
720
	}
721
	
722
	public boolean schemaTouches(int pos) {
723
		TextRange textRange = this.getSchemaCodeAssistTextRange();
724
		return (textRange != null) && (textRange.touches(pos));
725
	}
726
727
	public boolean catalogTouches(int pos) {
728
		TextRange textRange = this.getCatalogCodeAssistTextRange();
729
		return (textRange != null) && (textRange.touches(pos));
730
	}
702
}
731
}
(-)src/org/eclipse/jpt/jpa/core/resource/orm/XmlTableGenerator.java (-1 / +48 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2009 Oracle. All rights reserved.
2
 * Copyright (c) 2007, 2012 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 944-947 Link Here
944
	protected static Translator buildDescriptionTranslator() {
944
	protected static Translator buildDescriptionTranslator() {
945
		return new Translator(JPA.DESCRIPTION, OrmV2_0Package.eINSTANCE.getXmlGenerator_2_0_Description());
945
		return new Translator(JPA.DESCRIPTION, OrmV2_0Package.eINSTANCE.getXmlGenerator_2_0_Description());
946
	}
946
	}
947
948
	// ************* content assist ***************
949
	
950
	public TextRange getTableCodeAssistTextRange() {
951
		return getAttributeCodeAssistTextRange(JPA.TABLE);
952
	}
953
	
954
	public TextRange getSchemaCodeAssistTextRange() {
955
		return getAttributeCodeAssistTextRange(JPA.SCHEMA);
956
	}
957
	
958
	public TextRange getCatalogCodeAssistTextRange() {
959
		return getAttributeCodeAssistTextRange(JPA.CATALOG);
960
	}
961
	
962
	public TextRange getPKColumnNameTextRange() {
963
		return getAttributeCodeAssistTextRange(JPA.PK_COLUMN_NAME);
964
	}
965
	
966
	public TextRange getValueColumnNameTextRange() {
967
		return getAttributeCodeAssistTextRange(JPA.VALUE_COLUMN_NAME);
968
	}
969
	
970
	public boolean tableTouches(int pos) {
971
		TextRange textRange = this.getTableCodeAssistTextRange();
972
		return (textRange != null) && (textRange.touches(pos));
973
	}
974
975
	public boolean schemaTouches(int pos) {
976
		TextRange textRange = this.getSchemaCodeAssistTextRange();
977
		return (textRange != null) && (textRange.touches(pos));
978
	}
979
980
	public boolean catalogTouches(int pos) {
981
		TextRange textRange = this.getCatalogCodeAssistTextRange();
982
		return (textRange != null) && (textRange.touches(pos));
983
	}
984
985
	public boolean pkColumnNameTouches(int pos) {
986
		TextRange textRange = this.getPKColumnNameTextRange();
987
		return (textRange != null) && (textRange.touches(pos));
988
	}
989
990
	public boolean valueColumnNameTouches(int pos) {
991
		TextRange textRange = this.getValueColumnNameTextRange();
992
		return (textRange != null) && (textRange.touches(pos));
993
	}
947
}
994
}
(-)src/org/eclipse/jpt/jpa/core/resource/orm/XmlTypeMapping.java (-1 / +4 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2009, 2010 Oracle. All rights reserved.
2
 * Copyright (c) 2009, 2012 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 161-164 Link Here
161
161
162
	ReplaceEdit createRenamePackageEdit(String newName);
162
	ReplaceEdit createRenamePackageEdit(String newName);
163
163
164
	// ********** content assist *********
165
166
	boolean classNameTouches(int pos);
164
} // XmlTypeMapping
167
} // XmlTypeMapping
(-)src/org/eclipse/jpt/jpa/core/resource/orm/XmlUniqueConstraint.java (-1 / +13 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2009 Oracle. All rights reserved.
2
 * Copyright (c) 2007, 2012 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 17-22 Link Here
17
import org.eclipse.emf.ecore.impl.ENotificationImpl;
17
import org.eclipse.emf.ecore.impl.ENotificationImpl;
18
import org.eclipse.emf.ecore.util.EDataTypeEList;
18
import org.eclipse.emf.ecore.util.EDataTypeEList;
19
import org.eclipse.jpt.common.core.internal.utility.translators.SimpleTranslator;
19
import org.eclipse.jpt.common.core.internal.utility.translators.SimpleTranslator;
20
import org.eclipse.jpt.common.core.utility.TextRange;
20
import org.eclipse.jpt.jpa.core.resource.orm.v2_0.OrmV2_0Package;
21
import org.eclipse.jpt.jpa.core.resource.orm.v2_0.OrmV2_0Package;
21
import org.eclipse.jpt.jpa.core.resource.orm.v2_0.XmlUniqueConstraint_2_0;
22
import org.eclipse.jpt.jpa.core.resource.orm.v2_0.XmlUniqueConstraint_2_0;
22
import org.eclipse.jpt.jpa.core.resource.xml.AbstractJpaEObject;
23
import org.eclipse.jpt.jpa.core.resource.xml.AbstractJpaEObject;
Lines 271-274 Link Here
271
	protected static Translator buildColumnNameTranslator() {
272
	protected static Translator buildColumnNameTranslator() {
272
		return new Translator(JPA.COLUMN_NAME, OrmPackage.eINSTANCE.getXmlUniqueConstraint_ColumnNames());
273
		return new Translator(JPA.COLUMN_NAME, OrmPackage.eINSTANCE.getXmlUniqueConstraint_ColumnNames());
273
	}	
274
	}	
275
276
	// ************ content assist **********
277
	
278
	protected TextRange getColumnNameCodeAssistTextRange() {
279
		return this.getElementCodeAssistTextRange(JPA.COLUMN_NAME);
280
	}
281
	
282
	public boolean columnNamesTouches(int pos) {
283
		TextRange textRange = getColumnNameCodeAssistTextRange();
284
		return (textRange != null) && (textRange.touches(pos));
285
	}	
274
}
286
}
(-)src/org/eclipse/jpt/jpa/core/resource/xml/AbstractJpaEObject.java (-1 / +50 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2006, 2012 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 260-265 Link Here
260
	}
260
	}
261
261
262
262
263
	// ********** content assist **********
264
	
265
	/**
266
	 * Return a text range for the specified attribute node.
267
	 * If the attribute node does not exist, return null
268
	 * 
269
	 * This is used for content assist to return the exact text range of an attribute.
270
	 * It is different from the text range used by validation which returns
271
	 * the parent's text range if the specified attribute node does not exist
272
	 */
273
	protected TextRange getAttributeCodeAssistTextRange(String attributeName) {
274
		IDOMNode attributeNode = this.getAttributeNode(attributeName);
275
		return (attributeNode != null) ? this.buildTextRange(attributeNode) : null;
276
	}
277
	
278
	/**
279
	 * Return a text range for the specified element node.
280
	 * If the element node does not exist, return null
281
	 * 
282
	 * This is used for content assist to return the exact text range of an element.
283
	 * It is different from the text range used by validation which returns
284
	 * the parent's text range if the specified element node does not exist
285
	 */
286
	protected TextRange getElementCodeAssistTextRange(String elementName) {
287
		IDOMNode elementNode = this.getElementNode(elementName);
288
		return (elementNode != null) ? this.buildElementCodeAssistTextRange(elementNode) : null;
289
	}
290
	
291
	protected TextRange buildElementCodeAssistTextRange(IDOMNode domNode) {
292
		return (domNode == null) ? null : this.buildElementCodeAssistTextRange(domNode, null);
293
	}
294
	
295
	protected TextRange buildElementCodeAssistTextRange(IDOMNode domNode, TextRange textRange) {
296
		return (domNode == null) ? null : this.buildElementCodeAssistTextRange_(domNode, textRange);
297
	}
298
	/**
299
	 * pre-condition: the specified DOM node is not <code>null</code>
300
	 */
301
	protected TextRange buildElementCodeAssistTextRange_(IDOMNode domNode, TextRange textRange) {
302
		int offset = domNode.getStartOffset();
303
		int length = (domNode.getNodeType() == Node.ELEMENT_NODE) ?
304
						(((IDOMElement) domNode).getEndStartOffset() - offset) :
305
						domNode.getLength();
306
		int lineNumber = domNode.getStructuredDocument().getLineOfOffset(offset) + 1;
307
		return (textRange == null) ?
308
				new SimpleTextRange(offset, length, lineNumber) :
309
				textRange.buildTextRange(offset, length, lineNumber);
310
	}
311
263
	// ********** Refactoring TextEdits **********
312
	// ********** Refactoring TextEdits **********
264
	
313
	
265
	public DeleteEdit createDeleteEdit() {
314
	public DeleteEdit createDeleteEdit() {
(-)src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/java/JavaEclipseLinkConvert.java (-2 / +11 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2008, 2012 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-18 Link Here
9
 ******************************************************************************/
9
 ******************************************************************************/
10
package org.eclipse.jpt.jpa.eclipselink.core.internal.context.java;
10
package org.eclipse.jpt.jpa.eclipselink.core.internal.context.java;
11
11
12
import java.util.Arrays;
12
import org.eclipse.jdt.core.dom.CompilationUnit;
13
import org.eclipse.jdt.core.dom.CompilationUnit;
13
import org.eclipse.jpt.common.core.resource.java.Annotation;
14
import org.eclipse.jpt.common.core.resource.java.Annotation;
14
import org.eclipse.jpt.common.utility.Filter;
15
import org.eclipse.jpt.common.utility.Filter;
15
import org.eclipse.jpt.common.utility.internal.StringTools;
16
import org.eclipse.jpt.common.utility.internal.StringTools;
17
import org.eclipse.jpt.common.utility.internal.iterables.CompositeIterable;
16
import org.eclipse.jpt.common.utility.internal.iterables.FilteringIterable;
18
import org.eclipse.jpt.common.utility.internal.iterables.FilteringIterable;
17
import org.eclipse.jpt.jpa.core.JpaFactory;
19
import org.eclipse.jpt.jpa.core.JpaFactory;
18
import org.eclipse.jpt.jpa.core.context.Converter;
20
import org.eclipse.jpt.jpa.core.context.Converter;
Lines 141-148 Link Here
141
		return new FilteringIterable<String>(this.getConverterNames(), filter);
143
		return new FilteringIterable<String>(this.getConverterNames(), filter);
142
	}
144
	}
143
145
146
	/**
147
	 * @return names of the user-defined converters and of reserved converters
148
	 */
149
	@SuppressWarnings("unchecked")
144
	protected Iterable<String> getConverterNames() {
150
	protected Iterable<String> getConverterNames() {
145
		return this.getPersistenceUnit().getUniqueConverterNames();
151
		return new CompositeIterable<String>(
152
				this.getPersistenceUnit().getUniqueConverterNames(),
153
				Arrays.asList(EclipseLinkConvert.RESERVED_CONVERTER_NAMES)
154
				);
146
	}
155
	}
147
156
148
	@Override
157
	@Override
(-)src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/EclipseLinkOrmTenantDiscriminatorColumn2_3.java (-1 / +19 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2012 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the terms of
3
 * This program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0, which accompanies this distribution and is available at
4
 * the Eclipse Public License v1.0, which accompanies this distribution and is available at
5
 * http://www.eclipse.org/legal/epl-v10.html.
5
 * http://www.eclipse.org/legal/epl-v10.html.
Lines 249-252 Link Here
249
	protected NamedColumnTextRangeResolver buildTextRangeResolver() {
249
	protected NamedColumnTextRangeResolver buildTextRangeResolver() {
250
		return new OrmTableColumnTextRangeResolver(this);
250
		return new OrmTableColumnTextRangeResolver(this);
251
	}
251
	}
252
253
	// ********** completion proposals **********
254
255
	@Override
256
	public Iterable<String> getXmlCompletionProposals(int pos) {
257
		Iterable<String> result = super.getXmlCompletionProposals(pos);
258
		if (result != null) {
259
			return result;
260
		}
261
		if (this.tableTouches(pos)) {
262
			return this.getCandidateTableNames();
263
		}
264
		return null;
265
	}
266
267
	protected boolean tableTouches(int pos) {
268
		return this.xmlTenantDiscriminatorColumn.tableTouches(pos);
269
	}
252
}
270
}
(-)src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/OrmEclipseLinkArrayMapping2_3.java (+19 lines)
Lines 334-337 Link Here
334
	public JptValidator buildColumnValidator(ReadOnlyNamedColumn col, NamedColumnTextRangeResolver textRangeResolver) {
334
	public JptValidator buildColumnValidator(ReadOnlyNamedColumn col, NamedColumnTextRangeResolver textRangeResolver) {
335
		return new NamedColumnValidator(this.getPersistentAttribute(), (ReadOnlyBaseColumn) col, (TableColumnTextRangeResolver) textRangeResolver, new EntityTableDescriptionProvider());
335
		return new NamedColumnValidator(this.getPersistentAttribute(), (ReadOnlyBaseColumn) col, (TableColumnTextRangeResolver) textRangeResolver, new EntityTableDescriptionProvider());
336
	}
336
	}
337
	
338
	// ********** completion proposals **********
339
340
	@Override
341
	public Iterable<String> getXmlCompletionProposals(int pos) {
342
		Iterable<String> result = super.getXmlCompletionProposals(pos);
343
		if (result != null) {
344
			return result;
345
		}
346
		result = this.column.getXmlCompletionProposals(pos);
347
		if (result != null) {
348
			return result;
349
		}
350
		result = this.converter.getXmlCompletionProposals(pos);
351
		if (result != null) {
352
			return result;
353
		}
354
		return null;
355
	}
337
}
356
}
(-)src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/OrmEclipseLinkConvert.java (-1 / +30 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2008, 2012 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-15 Link Here
9
 ******************************************************************************/
9
 ******************************************************************************/
10
package org.eclipse.jpt.jpa.eclipselink.core.internal.context.orm;
10
package org.eclipse.jpt.jpa.eclipselink.core.internal.context.orm;
11
11
12
import java.util.Arrays;
12
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.iterables.CompositeIterable;
13
import org.eclipse.jpt.jpa.core.context.Converter;
15
import org.eclipse.jpt.jpa.core.context.Converter;
14
import org.eclipse.jpt.jpa.core.context.orm.OrmAttributeMapping;
16
import org.eclipse.jpt.jpa.core.context.orm.OrmAttributeMapping;
15
import org.eclipse.jpt.jpa.core.context.orm.OrmConverter;
17
import org.eclipse.jpt.jpa.core.context.orm.OrmConverter;
Lines 116-121 Link Here
116
		return this.getXmlConvertibleMapping().getConvertTextRange();
118
		return this.getXmlConvertibleMapping().getConvertTextRange();
117
	}
119
	}
118
120
121
	// ********** completion proposals **********
122
123
	@Override
124
	public Iterable<String> getXmlCompletionProposals(int pos) {
125
		Iterable<String> result = super.getXmlCompletionProposals(pos);
126
		if (result != null) {
127
			return result;
128
		}
129
		if (this.convertValueTouches(pos)) {
130
			return this.getConverterNames();
131
		}
132
		return null;
133
	}
134
135
	protected boolean convertValueTouches(int pos) {
136
		return this.getXmlConvertibleMapping().convertTouches(pos);
137
	}
138
139
	/**
140
	 * @return names of the user-defined converters and of reserved converters
141
	 */
142
	@SuppressWarnings("unchecked")
143
	protected Iterable<String> getConverterNames() {
144
		return new CompositeIterable<String>(
145
				this.getPersistenceUnit().getUniqueConverterNames(),
146
				Arrays.asList(EclipseLinkConvert.RESERVED_CONVERTER_NAMES));
147
	}
119
148
120
	// ********** adapter **********
149
	// ********** adapter **********
121
150
(-)src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/OrmEclipseLinkEntityImpl.java (+17 lines)
Lines 456-459 Link Here
456
	protected TextRange getParentClassTextRange() {
456
	protected TextRange getParentClassTextRange() {
457
		return this.getValidationTextRange(this.xmlTypeMapping.getParentClassTextRange());
457
		return this.getValidationTextRange(this.xmlTypeMapping.getParentClassTextRange());
458
	}
458
	}
459
	
460
461
	// ********** completion proposals **********
462
463
	@Override
464
	public Iterable<String> getXmlCompletionProposals(int pos) {
465
		Iterable<String> result = super.getXmlCompletionProposals(pos);
466
		if (result != null) {
467
			return result;
468
		}
469
		result = this.multitenancy.getXmlCompletionProposals(pos);
470
		if (result != null) {
471
			return result;
472
		}
473
		return null;
474
	}
475
459
}
476
}
(-)src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/OrmEclipseLinkMappedSuperclassImpl.java (+15 lines)
Lines 404-407 Link Here
404
	protected TextRange getParentClassTextRange() {
404
	protected TextRange getParentClassTextRange() {
405
		return this.getValidationTextRange(this.xmlTypeMapping.getParentClassTextRange());
405
		return this.getValidationTextRange(this.xmlTypeMapping.getParentClassTextRange());
406
	}
406
	}
407
408
	// ********** completion proposals **********
409
410
	@Override
411
	public Iterable<String> getXmlCompletionProposals(int pos) {
412
		Iterable<String> result = super.getXmlCompletionProposals(pos);
413
		if (result != null) {
414
			return result;
415
		}
416
		result = this.multitenancy.getXmlCompletionProposals(pos);
417
		if (result != null) {
418
			return result;
419
		}
420
		return null;
421
	}
407
}
422
}
(-)src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/OrmEclipseLinkMultitenancyImpl2_3.java (-1 / +18 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2012 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 775-778 Link Here
775
		XmlMultitenant_2_4 xmlMultitenant = this.getXmlMultitenant();
775
		XmlMultitenant_2_4 xmlMultitenant = this.getXmlMultitenant();
776
		return (xmlMultitenant == null) ? null : xmlMultitenant.getValidationTextRange();
776
		return (xmlMultitenant == null) ? null : xmlMultitenant.getValidationTextRange();
777
	}
777
	}
778
779
	// ********** completion proposals **********
780
781
	@Override
782
	public Iterable<String> getXmlCompletionProposals(int pos) {
783
		Iterable<String> result = super.getXmlCompletionProposals(pos);
784
		if (result != null) {
785
			return result;
786
		}
787
		for (OrmTenantDiscriminatorColumn2_3 tenantDiscriminatorColumn : this.getSpecifiedTenantDiscriminatorColumns()) {
788
			result = tenantDiscriminatorColumn.getXmlCompletionProposals(pos);
789
			if (result != null) {
790
				return result;
791
			}
792
		}
793
		return null;
794
	}
778
}
795
}
(-)src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/OrmEclipseLinkPersistenceUnitDefaults.java (-1 / +18 lines)
Lines 15-22 Link Here
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.LiveCloneListIterable;
16
import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneListIterable;
17
import org.eclipse.jpt.jpa.core.context.DiscriminatorType;
17
import org.eclipse.jpt.jpa.core.context.DiscriminatorType;
18
import org.eclipse.jpt.jpa.core.context.ReadOnlyNamedDiscriminatorColumn;
19
import org.eclipse.jpt.jpa.core.context.ReadOnlyNamedColumn;
18
import org.eclipse.jpt.jpa.core.context.ReadOnlyNamedColumn;
19
import org.eclipse.jpt.jpa.core.context.ReadOnlyNamedDiscriminatorColumn;
20
import org.eclipse.jpt.jpa.core.context.orm.OrmPersistenceUnitMetadata;
20
import org.eclipse.jpt.jpa.core.context.orm.OrmPersistenceUnitMetadata;
21
import org.eclipse.jpt.jpa.core.internal.context.JptValidator;
21
import org.eclipse.jpt.jpa.core.internal.context.JptValidator;
22
import org.eclipse.jpt.jpa.core.internal.context.NamedColumnTextRangeResolver;
22
import org.eclipse.jpt.jpa.core.internal.context.NamedColumnTextRangeResolver;
Lines 354-357 Link Here
354
			this.removeXmlDefaultsIfUnset();
354
			this.removeXmlDefaultsIfUnset();
355
		}
355
		}
356
	}
356
	}
357
358
	// ********** completion proposals **********
359
360
	@Override
361
	public Iterable<String> getXmlCompletionProposals(int pos) {
362
		Iterable<String> result = super.getXmlCompletionProposals(pos);
363
		if (result != null) {
364
			return result;
365
		}
366
		for (OrmTenantDiscriminatorColumn2_3 tenantDiscriminatorColumn : this.getTenantDiscriminatorColumns()) {
367
			result = tenantDiscriminatorColumn.getXmlCompletionProposals(pos);
368
			if (result != null) {
369
				return result;
370
			}
371
		}
372
		return null;
373
	}
357
}
374
}
(-)src/org/eclipse/jpt/jpa/eclipselink/core/resource/orm/XmlArray.java (+11 lines)
Lines 1289-1292 Link Here
1289
	protected static Translator buildAttributeTypeTranslator() {
1289
	protected static Translator buildAttributeTypeTranslator() {
1290
		return new Translator(EclipseLink2_3.ARRAY__ATTRIBUTE_TYPE, EclipseLinkOrmPackage.eINSTANCE.getXmlAttributeMapping_AttributeType(), Translator.DOM_ATTRIBUTE);
1290
		return new Translator(EclipseLink2_3.ARRAY__ATTRIBUTE_TYPE, EclipseLinkOrmPackage.eINSTANCE.getXmlAttributeMapping_AttributeType(), Translator.DOM_ATTRIBUTE);
1291
	}
1291
	}
1292
1293
	// *********** content assist ************
1294
	
1295
	protected TextRange getConvertCodeAssistTextRange() {
1296
		return getElementCodeAssistTextRange(EclipseLink.CONVERT);
1297
	}
1298
1299
	public boolean convertTouches(int pos) {
1300
		TextRange textRange = this.getConvertCodeAssistTextRange();
1301
		return (textRange != null) && (textRange.touches(pos));
1302
	}
1292
} // XmlArray
1303
} // XmlArray
(-)src/org/eclipse/jpt/jpa/eclipselink/core/resource/orm/XmlBasic.java (+10 lines)
Lines 1551-1554 Link Here
1551
		return new Translator(EclipseLink2_1.ATTRIBUTE_TYPE, EclipseLinkOrmPackage.eINSTANCE.getXmlAttributeMapping_AttributeType(), Translator.DOM_ATTRIBUTE);
1551
		return new Translator(EclipseLink2_1.ATTRIBUTE_TYPE, EclipseLinkOrmPackage.eINSTANCE.getXmlAttributeMapping_AttributeType(), Translator.DOM_ATTRIBUTE);
1552
	}
1552
	}
1553
1553
1554
	// *********** content assist ************
1555
	
1556
	protected TextRange getConvertCodeAssistTextRange() {
1557
		return getElementCodeAssistTextRange(EclipseLink.CONVERT);
1558
	}
1559
1560
	public boolean convertTouches(int pos) {
1561
		TextRange textRange = this.getConvertCodeAssistTextRange();
1562
		return (textRange != null) && (textRange.touches(pos));
1563
	}
1554
}
1564
}
(-)src/org/eclipse/jpt/jpa/eclipselink/core/resource/orm/XmlConvertibleMapping.java (-1 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2008, 2012 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 74-77 Link Here
74
	 */
74
	 */
75
	TextRange getConvertTextRange();
75
	TextRange getConvertTextRange();
76
76
77
	boolean convertTouches(int pos);
78
77
} // XmlConvertibleMapping
79
} // XmlConvertibleMapping
(-)src/org/eclipse/jpt/jpa/eclipselink/core/resource/orm/XmlElementCollection.java (+10 lines)
Lines 2304-2307 Link Here
2304
		return new EmptyTagBooleanTranslator(EclipseLink2_4.DELETE_ALL, EclipseLinkOrmV2_4Package.eINSTANCE.getXmlElementCollection_2_4_DeleteAll());
2304
		return new EmptyTagBooleanTranslator(EclipseLink2_4.DELETE_ALL, EclipseLinkOrmV2_4Package.eINSTANCE.getXmlElementCollection_2_4_DeleteAll());
2305
	}
2305
	}
2306
2306
2307
	// *********** content assist ************
2308
	
2309
	protected TextRange getConvertCodeAssistTextRange() {
2310
		return getElementCodeAssistTextRange(EclipseLink.CONVERT);
2311
	}
2312
2313
	public boolean convertTouches(int pos) {
2314
		TextRange textRange = this.getConvertCodeAssistTextRange();
2315
		return (textRange != null) && (textRange.touches(pos));
2316
	}
2307
}
2317
}
(-)src/org/eclipse/jpt/jpa/eclipselink/core/resource/orm/XmlId.java (-3 / +12 lines)
Lines 20-29 Link Here
20
import org.eclipse.emf.ecore.impl.ENotificationImpl;
20
import org.eclipse.emf.ecore.impl.ENotificationImpl;
21
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
21
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
22
import org.eclipse.emf.ecore.util.InternalEList;
22
import org.eclipse.emf.ecore.util.InternalEList;
23
import org.eclipse.jpt.common.core.internal.utility.translators.SimpleTranslator;
24
import org.eclipse.jpt.common.core.utility.TextRange;
23
import org.eclipse.jpt.jpa.core.resource.orm.JPA;
25
import org.eclipse.jpt.jpa.core.resource.orm.JPA;
24
import org.eclipse.jpt.jpa.core.resource.orm.OrmPackage;
26
import org.eclipse.jpt.jpa.core.resource.orm.OrmPackage;
25
import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.v2_1.EclipseLink2_1;
27
import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.v2_1.EclipseLink2_1;
26
import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.v2_1.EclipseLinkOrmV2_1Package;
27
import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.v2_2.EclipseLink2_2;
28
import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.v2_2.EclipseLink2_2;
28
import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.v2_2.EclipseLinkOrmV2_2Package;
29
import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.v2_2.EclipseLinkOrmV2_2Package;
29
import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.v2_2.XmlId_2_2;
30
import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.v2_2.XmlId_2_2;
Lines 32-39 Link Here
32
import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.v2_4.EclipseLinkOrmV2_4Package;
33
import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.v2_4.EclipseLinkOrmV2_4Package;
33
import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.v2_4.XmlCacheIndex_2_4;
34
import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.v2_4.XmlCacheIndex_2_4;
34
import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.v2_4.XmlId_2_4;
35
import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.v2_4.XmlId_2_4;
35
import org.eclipse.jpt.common.core.internal.utility.translators.SimpleTranslator;
36
import org.eclipse.jpt.common.core.utility.TextRange;
37
import org.eclipse.wst.common.internal.emf.resource.Translator;
36
import org.eclipse.wst.common.internal.emf.resource.Translator;
38
37
39
/**
38
/**
Lines 1098-1101 Link Here
1098
		return XmlTableGenerator.buildTranslator(JPA.TABLE_GENERATOR, OrmPackage.eINSTANCE.getXmlGeneratorContainer_TableGenerator());
1097
		return XmlTableGenerator.buildTranslator(JPA.TABLE_GENERATOR, OrmPackage.eINSTANCE.getXmlGeneratorContainer_TableGenerator());
1099
	}
1098
	}
1100
1099
1100
	// *********** content assist ************
1101
	
1102
	protected TextRange getConvertCodeAssistTextRange() {
1103
		return getElementCodeAssistTextRange(EclipseLink.CONVERT);
1104
	}
1105
1106
	public boolean convertTouches(int pos) {
1107
		TextRange textRange = this.getConvertCodeAssistTextRange();
1108
		return (textRange != null) && (textRange.touches(pos));
1109
	}
1101
}
1110
}
(-)src/org/eclipse/jpt/jpa/eclipselink/core/resource/orm/XmlTenantDiscriminatorColumn.java (-1 / +11 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 *  Copyright (c) 2011  Oracle. All rights reserved.
2
 *  Copyright (c) 2012  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 401-404 Link Here
401
	protected static Translator buildPrimaryKeyTranslator() {
401
	protected static Translator buildPrimaryKeyTranslator() {
402
		return new Translator(EclipseLink2_3.TENANT_DISCRIMINATOR_COLUMN__PRIMARY_KEY, EclipseLinkOrmV2_3Package.eINSTANCE.getXmlTenantDiscriminatorColumn_2_3_PrimaryKey(), Translator.DOM_ATTRIBUTE);
402
		return new Translator(EclipseLink2_3.TENANT_DISCRIMINATOR_COLUMN__PRIMARY_KEY, EclipseLinkOrmV2_3Package.eINSTANCE.getXmlTenantDiscriminatorColumn_2_3_PrimaryKey(), Translator.DOM_ATTRIBUTE);
403
	}
403
	}
404
	// *********** content assist ***********
405
	
406
	public TextRange getTableCodeAssistTextRange() {
407
		return getAttributeCodeAssistTextRange(EclipseLink2_3.TENANT_DISCRIMINATOR_COLUMN__TABLE);
408
	}
409
410
	public boolean tableTouches(int pos) {
411
		TextRange textRange = this.getTableCodeAssistTextRange();
412
		return (textRange != null) && (textRange.touches(pos));
413
	}
404
} // XmlTenantDiscriminator
414
} // XmlTenantDiscriminator
(-)src/org/eclipse/jpt/jpa/eclipselink/core/resource/orm/XmlVersion.java (-2 / +12 lines)
Lines 20-33 Link Here
20
import org.eclipse.emf.ecore.impl.ENotificationImpl;
20
import org.eclipse.emf.ecore.impl.ENotificationImpl;
21
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
21
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
22
import org.eclipse.emf.ecore.util.InternalEList;
22
import org.eclipse.emf.ecore.util.InternalEList;
23
import org.eclipse.jpt.common.core.internal.utility.translators.SimpleTranslator;
24
import org.eclipse.jpt.common.core.utility.TextRange;
23
import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.v2_1.EclipseLink2_1;
25
import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.v2_1.EclipseLink2_1;
24
import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.v2_1.EclipseLinkOrmV2_1Package;
26
import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.v2_1.EclipseLinkOrmV2_1Package;
25
import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.v2_2.EclipseLink2_2;
27
import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.v2_2.EclipseLink2_2;
26
import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.v2_2.EclipseLinkOrmV2_2Package;
28
import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.v2_2.EclipseLinkOrmV2_2Package;
27
import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.v2_2.XmlIndex_2_2;
29
import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.v2_2.XmlIndex_2_2;
28
import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.v2_2.XmlVersion_2_2;
30
import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.v2_2.XmlVersion_2_2;
29
import org.eclipse.jpt.common.core.internal.utility.translators.SimpleTranslator;
30
import org.eclipse.jpt.common.core.utility.TextRange;
31
import org.eclipse.wst.common.internal.emf.resource.Translator;
31
import org.eclipse.wst.common.internal.emf.resource.Translator;
32
32
33
/**
33
/**
Lines 977-980 Link Here
977
		return new Translator(EclipseLink2_1.ATTRIBUTE_TYPE, EclipseLinkOrmPackage.eINSTANCE.getXmlAttributeMapping_AttributeType(), Translator.DOM_ATTRIBUTE);
977
		return new Translator(EclipseLink2_1.ATTRIBUTE_TYPE, EclipseLinkOrmPackage.eINSTANCE.getXmlAttributeMapping_AttributeType(), Translator.DOM_ATTRIBUTE);
978
	}
978
	}
979
979
980
	// *********** content assist ************
981
	
982
	protected TextRange getConvertCodeAssistTextRange() {
983
		return getElementCodeAssistTextRange(EclipseLink.CONVERT);
984
	}
985
986
	public boolean convertTouches(int pos) {
987
		TextRange textRange = this.getConvertCodeAssistTextRange();
988
		return (textRange != null) && (textRange.touches(pos));
989
	}
980
}
990
}
(-)src/org/eclipse/jpt/jpa/eclipselink/core/resource/orm/v2_3/XmlTenantDiscriminatorColumn_2_3.java (-1 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 *  Copyright (c) 2011  Oracle. All rights reserved.
2
 *  Copyright (c) 2012  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 113-116 Link Here
113
	void setPrimaryKey(Boolean value);
113
	void setPrimaryKey(Boolean value);
114
114
115
	TextRange getTableTextRange();
115
	TextRange getTableTextRange();
116
117
	boolean tableTouches(int pos);
116
} // XmlTenantDiscriminator2_3
118
} // XmlTenantDiscriminator2_3
(-)META-INF/MANIFEST.MF (-1 / +4 lines)
Lines 41-49 Link Here
41
 org.eclipse.wst.common.emf;bundle-version="[1.1.200,2.0.0)",
41
 org.eclipse.wst.common.emf;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.frameworks.ui;bundle-version="[1.1.200,2.0.0)",
43
 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)",
44
 org.eclipse.wst.sse.core;bundle-version="[1.1.700,2.0.0)",
44
 org.eclipse.wst.sse.ui;bundle-version="[1.1.0,2.0.0)",
45
 org.eclipse.wst.sse.ui;bundle-version="[1.1.0,2.0.0)",
45
 org.eclipse.wst.validation;bundle-version="[1.2.0,2.0.0)",
46
 org.eclipse.wst.validation;bundle-version="[1.2.0,2.0.0)",
46
 org.eclipse.wst.web.ui;bundle-version="[1.1.200,2.0.0)"
47
 org.eclipse.wst.web.ui;bundle-version="[1.1.200,2.0.0)",
48
 org.eclipse.wst.xml.core;bundle-version="[1.1.700,2.0.0)",
49
 org.eclipse.wst.xml.ui;bundle-version="[1.1.300,2.0.0)"
47
Export-Package: org.eclipse.jpt.jpa.ui,
50
Export-Package: org.eclipse.jpt.jpa.ui,
48
 org.eclipse.jpt.jpa.ui.details,
51
 org.eclipse.jpt.jpa.ui.details,
49
 org.eclipse.jpt.jpa.ui.details.java,
52
 org.eclipse.jpt.jpa.ui.details.java,
(-)plugin.xml (+21 lines)
Lines 181-186 Link Here
181
181
182
	</extension>
182
	</extension>
183
183
184
	<extension
185
       id="org.eclipse.jpt.jpa.ui.xml.xmlCompletionProposal"
186
       point="org.eclipse.wst.sse.ui.completionProposal">
187
188
		<proposalCategory
189
	           icon="$nl$/icons/full/eview16/jpa_perspective.gif"
190
	           id="org.eclipse.jpt.jpa.ui.xml.xmlProposalCategory"
191
	           name="%JpaProposalCategory">
192
		</proposalCategory>
193
194
		<proposalComputer
195
	       activate="true"
196
	       categoryId="org.eclipse.jpt.jpa.ui.xml.xmlProposalCategory"
197
	       class="org.eclipse.jpt.jpa.ui.internal.JpaXmlCompletionProposalComputer"
198
	       id="org.eclipse.jpt.jpa.ui.internal.JpaXmlCompletionProposalComputer">
199
			<contentType
200
				id="org.eclipse.core.runtime.xml">
201
			</contentType>
202
		</proposalComputer>
203
204
	</extension>
184
205
185
	<!-- ***** Dali extensions (eat our own dogfood) ***** -->
206
	<!-- ***** Dali extensions (eat our own dogfood) ***** -->
186
207
(-)src/org/eclipse/jpt/jpa/ui/internal/AbstractJpaXmlCompletionProposalComputer.java (+1097 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2012 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     
11
 *******************************************************************************/
12
package org.eclipse.jpt.jpa.ui.internal;
13
14
import java.util.ArrayList;
15
import java.util.Arrays;
16
import java.util.Collections;
17
import java.util.Iterator;
18
import java.util.List;
19
import java.util.Properties;
20
import java.util.Vector;
21
22
import org.eclipse.core.runtime.IProgressMonitor;
23
import org.eclipse.jface.text.BadLocationException;
24
import org.eclipse.jface.text.ITextViewer;
25
import org.eclipse.jface.text.contentassist.ICompletionProposal;
26
import org.eclipse.wst.sse.core.StructuredModelManager;
27
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
28
import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
29
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
30
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
31
import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
32
import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer;
33
import org.eclipse.wst.sse.ui.contentassist.CompletionProposalInvocationContext;
34
import org.eclipse.wst.sse.ui.contentassist.ICompletionProposalComputer;
35
import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils;
36
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
37
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
38
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
39
import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
40
import org.eclipse.wst.xml.ui.internal.Logger;
41
import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
42
import org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest;
43
import org.w3c.dom.Document;
44
import org.w3c.dom.Node;
45
import org.w3c.dom.NodeList;
46
47
/**
48
 * <p>Implements the framework for making proposals in XML type documents.  Deals with
49
 * all the nastiness needed to figure out where in an XML type document the content
50
 * assist was invoked and then calls one of many abstract methods depending on the
51
 * area the content assist was invoked.  In this way implementers only have to worry about
52
 * implementing what to do in each situation while not having to deal with figuring out
53
 * which situation the content assist was invoked in.</p>
54
 * 
55
 * @base org.eclipse.wst.xml.ui.internal.contentassist.AbstractContentAssistProcessor
56
 * @see DefaultJpaXmlCompletionProposalComputer
57
 * 
58
 * The code of this class was copied from AbstractXMLCompletionProposalComputer and modified according to
59
 * the needs of the XML content assist of Dali. This class can be removed after bug 371939 is addressed.
60
 */
61
62
public abstract class AbstractJpaXmlCompletionProposalComputer implements ICompletionProposalComputer {
63
64
	private String fErrorMessage;
65
	private ITextViewer fTextViewer;
66
67
	public AbstractJpaXmlCompletionProposalComputer() {
68
		fErrorMessage = null;
69
		fTextViewer = null;
70
	}
71
72
	/**
73
	 * <p>Return a list of proposed code completions based on the specified
74
	 * location within the document that corresponds to the current cursor
75
	 * position within the text-editor control.</p>
76
	 * 
77
	 * @see org.eclipse.wst.sse.ui.contentassist.ICompletionProposalComputer#computeCompletionProposals(org.eclipse.wst.sse.ui.contentassist.CompletionProposalInvocationContext, org.eclipse.core.runtime.IProgressMonitor)
78
	 */
79
	public List<ICompletionProposal> computeCompletionProposals(
80
			CompletionProposalInvocationContext context,
81
			IProgressMonitor monitor) {
82
83
		ITextViewer textViewer = context.getViewer();
84
		int documentPosition = context.getInvocationOffset();
85
86
		setErrorMessage(null);
87
88
		fTextViewer = textViewer;
89
90
		IndexedRegion treeNode = ContentAssistUtils.getNodeAt(textViewer, documentPosition);
91
92
		Node node = (Node) treeNode;
93
		while ((node != null) && (node.getNodeType() == Node.TEXT_NODE) && (node.getParentNode() != null)) {
94
			node = node.getParentNode();
95
		}
96
		IDOMNode xmlnode = (IDOMNode) node;
97
98
		ContentAssistRequest contentAssistRequest = null;
99
100
		IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition);
101
		ITextRegion completionRegion = getCompletionRegion(documentPosition, node);
102
103
		String matchString = null;
104
		try {
105
			matchString = getMatchString(sdRegion, completionRegion, documentPosition);
106
		} catch (BadLocationException e) {
107
			e.printStackTrace();
108
		}
109
110
		// Handle empty Documents
111
		if (completionRegion == null) {
112
			if (((treeNode == null) || (((Node) treeNode).getNodeType() == Node.DOCUMENT_NODE)) && (completionRegion == null) &&
113
					((xmlnode == null) || (xmlnode.getChildNodes() == null) || (xmlnode.getChildNodes().getLength() == 0))) {
114
115
				IStructuredModel sModel = null;
116
				try {
117
					if(textViewer.getDocument() instanceof IStructuredDocument) {
118
						sModel = StructuredModelManager.getModelManager().getModelForRead((IStructuredDocument)textViewer.getDocument());
119
					}
120
					if (sModel != null) {
121
						IDOMDocument docNode = ((IDOMModel) sModel).getDocument();
122
						contentAssistRequest = new ContentAssistRequest(docNode, docNode, sdRegion, completionRegion, documentPosition, 0, null);
123
						addEmptyDocumentProposals(contentAssistRequest, context);
124
					}
125
				}
126
				finally {
127
					if (sModel != null) {
128
						sModel.releaseFromRead();
129
					}
130
				}
131
				if (contentAssistRequest == null) {
132
					Logger.logException(new IllegalStateException("problem getting model")); //$NON-NLS-1$
133
					return new ArrayList<ICompletionProposal>(0);
134
				}
135
136
				ICompletionProposal[] props = contentAssistRequest.getCompletionProposals();
137
				return (props != null) ? Arrays.asList(props) : new ArrayList<ICompletionProposal>(0);
138
			}
139
			// MASSIVE ERROR CONDITION
140
			Logger.logException(new IllegalStateException("completion region was null")); //$NON-NLS-1$
141
			setErrorMessage(XMLUIMessages.SEVERE_internal_error_occu_UI_);
142
			contentAssistRequest = new ContentAssistRequest((Node) treeNode, node.getParentNode(), sdRegion, completionRegion, documentPosition, 0, ""); //$NON-NLS-1$
143
			ICompletionProposal[] props = contentAssistRequest.getCompletionProposals();
144
			return (props != null) ? Arrays.asList(props) : new ArrayList<ICompletionProposal>(0);
145
		}
146
147
148
		// catch documents where no region can be determined
149
		if ((xmlnode.getNodeType() == Node.DOCUMENT_NODE) && ((completionRegion == null) ||
150
				(xmlnode.getChildNodes() == null) || (xmlnode.getChildNodes().getLength() == 0))) {
151
152
			contentAssistRequest = computeStartDocumentProposals(matchString, completionRegion,
153
					(IDOMNode) treeNode,xmlnode, context);
154
			ICompletionProposal[] props = contentAssistRequest.getCompletionProposals();
155
			return (props != null) ? Arrays.asList(props) : new ArrayList<ICompletionProposal>(0);
156
		}
157
158
		// compute normal proposals
159
		contentAssistRequest = computeCompletionProposals(matchString, completionRegion, (IDOMNode) treeNode, xmlnode, context);
160
		if (contentAssistRequest == null) {
161
			contentAssistRequest = new ContentAssistRequest((Node) treeNode, node.getParentNode(), sdRegion, completionRegion, documentPosition, 0, ""); //$NON-NLS-1$
162
			setErrorMessage(XMLUIMessages.Content_Assist_not_availab_UI_);
163
		}
164
165
		/* 
166
		 * Only set this error message if nothing else was already set 
167
		 **/
168
		if (contentAssistRequest.getProposals().size() == 0 && getErrorMessage() == null) {
169
			setErrorMessage(XMLUIMessages.Content_Assist_not_availab_UI_);
170
		}
171
172
		ICompletionProposal[] props = contentAssistRequest.getCompletionProposals();
173
		return (props != null) ? Arrays.asList(props) : new ArrayList<ICompletionProposal>(0);
174
	}
175
176
	/**
177
	 * <p>Returns information about possible contexts based on the specified
178
	 * location within the document that corresponds to the current cursor
179
	 * position within the text viewer.</p>
180
	 * 
181
	 * @see org.eclipse.wst.sse.ui.contentassist.ICompletionProposalComputer#computeContextInformation(org.eclipse.wst.sse.ui.contentassist.CompletionProposalInvocationContext, org.eclipse.core.runtime.IProgressMonitor)
182
	 */
183
	public List<ICompletionProposal> computeContextInformation(
184
			CompletionProposalInvocationContext context,
185
			IProgressMonitor monitor) {
186
187
		//no default context info
188
		return Collections.emptyList();
189
	}
190
191
	/**
192
	 * @see org.eclipse.wst.sse.ui.contentassist.ICompletionProposalComputer#getErrorMessage()
193
	 */
194
	public String getErrorMessage() {
195
		return fErrorMessage;
196
	}
197
198
	/**
199
	 * Add proposals for attribute names
200
	 * 
201
	 * @param contentAssistRequest
202
	 * @param context
203
	 */
204
	protected abstract void addAttributeNameProposals(ContentAssistRequest contentAssistRequest,
205
			CompletionProposalInvocationContext context);
206
207
	/**
208
	 * Add proposals for attribute values
209
	 * 
210
	 * @param contentAssistRequest
211
	 * @param context
212
	 */
213
	protected abstract void addAttributeValueProposals(ContentAssistRequest contentAssistRequest,
214
			CompletionProposalInvocationContext context);
215
216
	/**
217
	 * Add comment proposals
218
	 * 
219
	 * @param contentAssistRequest
220
	 * @param context
221
	 */
222
	protected abstract void addCommentProposal(ContentAssistRequest contentAssistRequest,
223
			CompletionProposalInvocationContext context);
224
225
	/**
226
	 * Add the proposals for a completely empty document
227
	 * 
228
	 * @param contentAssistRequest
229
	 * @param context
230
	 */
231
	protected abstract void addEmptyDocumentProposals(ContentAssistRequest contentAssistRequest,
232
			CompletionProposalInvocationContext context);
233
234
	/**
235
	 * Add the proposals for the name in an end tag
236
	 * 
237
	 * @param contentAssistRequest
238
	 * @param context
239
	 */
240
	protected abstract void addEndTagNameProposals(ContentAssistRequest contentAssistRequest,
241
			CompletionProposalInvocationContext context);
242
243
	/**
244
	 * Prompt for end tags to a non-empty Node that hasn't ended Handles these
245
	 * cases: <br>
246
	 * <tagOpen>| <br>
247
	 * <tagOpen>< |<br>
248
	 * <tagOpen></ |
249
	 * 
250
	 * @param contentAssistRequest
251
	 * @param context
252
	 */
253
	protected abstract void addEndTagProposals(ContentAssistRequest contentAssistRequest,
254
			CompletionProposalInvocationContext context);
255
256
	/**
257
	 * Add entity proposals
258
	 * 
259
	 * @param contentAssistRequest
260
	 * @param completionRegion
261
	 * @param treeNode
262
	 * @param context
263
	 */
264
	protected abstract void addEntityProposals(ContentAssistRequest contentAssistRequest,
265
			ITextRegion completionRegion, IDOMNode treeNode, CompletionProposalInvocationContext context);
266
267
	/**
268
	 * add entity proposals
269
	 * 
270
	 * @param proposals
271
	 * @param map
272
	 * @param key
273
	 * @param nodeOffset
274
	 * @param sdRegion
275
	 * @param completionRegion
276
	 * @param context
277
	 */
278
	protected abstract void addEntityProposals(Vector<ICompletionProposal> proposals, Properties map, String key,
279
			int nodeOffset, IStructuredDocumentRegion sdRegion, ITextRegion completionRegion,
280
			CompletionProposalInvocationContext context);
281
282
	/**
283
	 * Add PCData proposals
284
	 * 
285
	 * @param nodeName
286
	 * @param contentAssistRequest
287
	 * @param context
288
	 */
289
	protected abstract void addPCDATAProposal(String nodeName, ContentAssistRequest contentAssistRequest,
290
			CompletionProposalInvocationContext context);
291
292
	/**
293
	 * Add start document proposals
294
	 * 
295
	 * @param contentAssistRequest
296
	 * @param context
297
	 */
298
	protected abstract void addStartDocumentProposals(ContentAssistRequest contentAssistRequest,
299
			CompletionProposalInvocationContext context);
300
301
	/**
302
	 * Close an unclosed start tag
303
	 * 
304
	 * @param contentAssistRequest
305
	 * @param context
306
	 */
307
	protected abstract void addTagCloseProposals(ContentAssistRequest contentAssistRequest,
308
			CompletionProposalInvocationContext context);
309
310
	/**
311
	 * Add tag insertion proposals
312
	 * 
313
	 * @param contentAssistRequest
314
	 * @param childPosition
315
	 * @param context
316
	 */
317
	protected abstract void addTagInsertionProposals(ContentAssistRequest contentAssistRequest,
318
			int childPosition, CompletionProposalInvocationContext context);
319
320
	/**
321
	 * Add tag name proposals
322
	 * 
323
	 * @param contentAssistRequest
324
	 * @param childPosition
325
	 * @param context
326
	 */
327
	protected abstract void addTagNameProposals(ContentAssistRequest contentAssistRequest,
328
			int childPosition, CompletionProposalInvocationContext context);
329
330
	/**
331
	 * @param errorMessage the reason why computeProposals was not able to find any
332
	 * completions.
333
	 */
334
	protected void setErrorMessage(String errorMessage) {
335
		fErrorMessage = errorMessage;
336
	}
337
338
	/**
339
	 * <p>This does all the magic of figuring out where in the XML type document
340
	 * the content assist was invoked and then calling the corresponding method
341
	 * to add the correct proposals</p>
342
	 * 
343
	 * <p><b>NOTE: </b>if overriding be sure to make super call back to this method otherwise
344
	 * you will loose all of the proposals generated by this method</p>
345
	 * 
346
	 * @param matchString
347
	 * @param completionRegion
348
	 * @param treeNode
349
	 * @param xmlnode
350
	 * @param context
351
	 * 
352
	 * @return {@link ContentAssistRequest} that now has all the proposals in it
353
	 */
354
	protected ContentAssistRequest computeCompletionProposals(String matchString, ITextRegion completionRegion,
355
			IDOMNode treeNode, IDOMNode xmlnode, CompletionProposalInvocationContext context) {
356
		int documentPosition = context.getInvocationOffset();
357
358
		ContentAssistRequest contentAssistRequest = null;
359
		String regionType = completionRegion.getType();
360
		IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition);
361
362
		// Handle the most common and best supported cases
363
		if ((xmlnode.getNodeType() == Node.ELEMENT_NODE) || (xmlnode.getNodeType() == Node.DOCUMENT_NODE)) {
364
			if (regionType == DOMRegionContext.XML_TAG_OPEN) {
365
				contentAssistRequest = computeTagOpenProposals(matchString, completionRegion, treeNode, xmlnode, context);
366
			}
367
			else if (regionType == DOMRegionContext.XML_TAG_NAME) {
368
				contentAssistRequest = computeTagNameProposals(matchString, completionRegion,
369
						treeNode, xmlnode, context);
370
			}
371
			else if (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) {
372
				contentAssistRequest = computeAttributeProposals(matchString, completionRegion, treeNode, xmlnode, context);
373
			}
374
			else if (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) {
375
				contentAssistRequest = computeEqualsProposals(matchString, completionRegion,
376
						treeNode, xmlnode, context);
377
			}
378
			else if ((regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) && (documentPosition == sdRegion.getTextEndOffset()) &&
379
					(sdRegion.getText(completionRegion).endsWith("\"") || sdRegion.getText(completionRegion).endsWith("\'"))) { //$NON-NLS-1$ //$NON-NLS-2$ 
380
				// this is for when the cursor is at the end of the closing quote for an attribute..
381
				IDOMNode actualNode = (IDOMNode) xmlnode.getModel().getIndexedRegion(sdRegion.getStartOffset(completionRegion));
382
				contentAssistRequest = new ContentAssistRequest(actualNode, actualNode, sdRegion, completionRegion, documentPosition, 0, matchString);
383
				addTagCloseProposals(contentAssistRequest, context);
384
			}
385
			else if (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
386
				contentAssistRequest = computeAttributeValueProposals(matchString, completionRegion, treeNode, xmlnode, context);
387
			}
388
			else if ((regionType == DOMRegionContext.XML_TAG_CLOSE) || (regionType == DOMRegionContext.XML_EMPTY_TAG_CLOSE)) {
389
390
				contentAssistRequest = computeTagCloseProposals(matchString, completionRegion, treeNode, xmlnode, context);
391
			}
392
			else if (regionType == DOMRegionContext.XML_END_TAG_OPEN) {
393
				contentAssistRequest = computeEndTagOpenProposals(matchString, completionRegion,
394
						treeNode, xmlnode, context);
395
			}
396
			else if ((regionType == DOMRegionContext.XML_CONTENT) || (regionType == DOMRegionContext.XML_CHAR_REFERENCE) ||
397
					(regionType == DOMRegionContext.XML_ENTITY_REFERENCE) || (regionType == DOMRegionContext.XML_PE_REFERENCE)) {
398
399
				contentAssistRequest = computeContentProposals(matchString, completionRegion,
400
						treeNode, xmlnode, context);
401
			}
402
403
			// These ITextRegion types begin DOM Elements as well and although
404
			// internally harder to assist, text insertions directly before them can be made
405
			else if ((documentPosition == sdRegion.getStartOffset(completionRegion)) &&
406
					((regionType == DOMRegionContext.XML_DECLARATION_OPEN) ||
407
							(regionType == DOMRegionContext.XML_PI_OPEN) ||
408
							(regionType == DOMRegionContext.XML_COMMENT_OPEN) ||
409
							(regionType == DOMRegionContext.XML_CDATA_OPEN))) {
410
411
				contentAssistRequest = new ContentAssistRequest(treeNode, xmlnode.getParentNode(), sdRegion, completionRegion, documentPosition, 0, matchString);
412
				addTagInsertionProposals(contentAssistRequest, getElementPosition(treeNode), context);
413
				addStartDocumentProposals(contentAssistRequest, context);
414
			}
415
		}
416
		// Not a Document or Element
417
		else if (isCloseRegion(completionRegion)) {
418
			contentAssistRequest = new ContentAssistRequest(treeNode, xmlnode.getParentNode(), sdRegion, completionRegion, sdRegion.getStartOffset(completionRegion) + completionRegion.getLength(), 0, matchString);
419
			addStartDocumentProposals(contentAssistRequest, context);
420
			if (documentPosition >= sdRegion.getTextEndOffset(completionRegion)) {
421
				addTagInsertionProposals(contentAssistRequest, getElementPosition(treeNode) + 1, context);
422
			}
423
		}
424
		else if ((documentPosition == sdRegion.getStartOffset(completionRegion)) &&
425
				((regionType == DOMRegionContext.XML_DECLARATION_OPEN) ||
426
						(regionType == DOMRegionContext.XML_PI_OPEN) ||
427
						(regionType == DOMRegionContext.XML_COMMENT_OPEN) ||
428
						(regionType == DOMRegionContext.XML_CDATA_OPEN))) {
429
430
			contentAssistRequest = new ContentAssistRequest(treeNode, xmlnode.getParentNode(), sdRegion, completionRegion, documentPosition, 0, matchString);
431
			addTagInsertionProposals(contentAssistRequest, getElementPosition(treeNode), context);
432
			addStartDocumentProposals(contentAssistRequest, context);
433
		}
434
		return contentAssistRequest;
435
	}
436
437
	/**
438
	 * <p>Similar to {@link #computeCompletionProposals(CompletionProposalInvocationContext, IProgressMonitor)} only specificly for
439
	 * attribute proposals</p>
440
	 * 
441
	 * <p>Implementers should not override this method, it is made available to implementers so that if they override
442
	 * {@link #computeCompletionProposals(String, ITextRegion, IDOMNode, IDOMNode, CompletionProposalInvocationContext)}
443
	 * they can call this method if needed</p>
444
	 * 
445
	 * @param matchString
446
	 * @param completionRegion
447
	 * @param nodeAtOffset
448
	 * @param node
449
	 * @param context
450
	 * @return
451
	 */
452
	protected final ContentAssistRequest computeAttributeProposals(String matchString, ITextRegion completionRegion,
453
			IDOMNode nodeAtOffset, IDOMNode node, CompletionProposalInvocationContext context) {
454
455
		int documentPosition = context.getInvocationOffset();
456
		ITextViewer viewer = context.getViewer();
457
		ContentAssistRequest contentAssistRequest = null;
458
		IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition);
459
		// if the attribute name is selected, replace it instead of creating a new attribute
460
		if (documentPosition <= sdRegion.getStartOffset(completionRegion) && (viewer != null && viewer.getSelectedRange().y != (sdRegion.getEndOffset(completionRegion) - sdRegion.getStartOffset(completionRegion)))) {
461
			// setup to insert new attributes
462
			contentAssistRequest = new ContentAssistRequest(nodeAtOffset, node, sdRegion, completionRegion, documentPosition, 0, matchString);
463
		}
464
		else {
465
			// Setup to replace an existing attribute name
466
			contentAssistRequest = new ContentAssistRequest(nodeAtOffset, node, sdRegion, completionRegion, sdRegion.getStartOffset(completionRegion), completionRegion.getTextLength(), matchString);
467
		}
468
		addAttributeNameProposals(contentAssistRequest, context);
469
		contentAssistRequest.setReplacementBeginPosition(documentPosition);
470
		contentAssistRequest.setReplacementLength(0);
471
		if ((node.getFirstStructuredDocumentRegion() != null) && (!node.getFirstStructuredDocumentRegion().isEnded())) {
472
			addTagCloseProposals(contentAssistRequest, context);
473
		}
474
		return contentAssistRequest;
475
	}
476
477
	/**
478
	 * <p>this is the position the cursor should be in after the proposal is
479
	 * applied</p>
480
	 * 
481
	 * @param proposedText
482
	 * @return the position the cursor should be in after the proposal is
483
	 *         applied
484
	 */
485
	protected static int getCursorPositionForProposedText(String proposedText) {
486
		int cursorAdjustment;
487
		cursorAdjustment = proposedText.indexOf("\"\"") + 1; //$NON-NLS-1$
488
		// otherwise, after the first tag
489
		if (cursorAdjustment == 0) {
490
			cursorAdjustment = proposedText.indexOf('>') + 1;
491
		}
492
		if (cursorAdjustment == 0) {
493
			cursorAdjustment = proposedText.length() + 1;
494
		}
495
496
		return cursorAdjustment;
497
	}
498
499
	/**
500
	 * <p>helpful utility method for determining if one string starts with another one.
501
	 * This is case insensitive. If either are null then result is <code>true</code></p>
502
	 * 
503
	 * @param aString the string to check to see if it starts with the given prefix
504
	 * @param prefix check that the given string starts with this prefix
505
	 * 
506
	 * @return <code>true</code> if the given string starts with the given prefix,
507
	 * <code>false</code> otherwise
508
	 */
509
	protected static boolean beginsWith(String aString, String prefix) {
510
		if ((aString == null) || (prefix == null)) {
511
			return true;
512
		}
513
		return aString.toLowerCase().startsWith(prefix.toLowerCase());
514
	}
515
516
	private ContentAssistRequest computeAttributeValueProposals(String matchString, ITextRegion completionRegion,
517
			IDOMNode nodeAtOffset, IDOMNode node, CompletionProposalInvocationContext context) {
518
519
		int documentPosition = context.getInvocationOffset();
520
521
		ContentAssistRequest contentAssistRequest = null;
522
		IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition);
523
		if ((documentPosition > sdRegion.getStartOffset(completionRegion) + completionRegion.getTextLength()) && (sdRegion.getStartOffset(completionRegion) + completionRegion.getTextLength() != sdRegion.getStartOffset(completionRegion) + completionRegion.getLength())) {
524
			// setup to add a new attribute at the documentPosition
525
			IDOMNode actualNode = (IDOMNode) node.getModel().getIndexedRegion(sdRegion.getStartOffset(completionRegion));
526
			contentAssistRequest = new ContentAssistRequest(actualNode, actualNode, sdRegion, completionRegion, documentPosition, 0, matchString);
527
			addAttributeNameProposals(contentAssistRequest, context);
528
			if ((actualNode.getFirstStructuredDocumentRegion() != null) && !actualNode.getFirstStructuredDocumentRegion().isEnded()) {
529
				addTagCloseProposals(contentAssistRequest, context);
530
			}
531
		}
532
		else {
533
			// setup to replace the existing value
534
			if (!nodeAtOffset.getFirstStructuredDocumentRegion().isEnded() && (documentPosition < sdRegion.getStartOffset(completionRegion))) {
535
				// if the IStructuredDocumentRegion isn't closed and the
536
				// cursor is in front of the value, add
537
				contentAssistRequest = new ContentAssistRequest(nodeAtOffset, node, sdRegion, completionRegion, documentPosition, 0, matchString);
538
				addAttributeNameProposals(contentAssistRequest, context);
539
			}
540
			else {
541
				int replaceLength = completionRegion.getTextLength();
542
543
				//if container region, be sure replace length is only the attribute value region not the entire container
544
				if(completionRegion instanceof ITextRegionContainer){
545
					ITextRegion openRegion = ((ITextRegionContainer) completionRegion).getFirstRegion();
546
					ITextRegion closeRegion = ((ITextRegionContainer) completionRegion).getLastRegion();
547
548
					/*
549
					 * check to see if the container is opened the same way its closed.
550
					 * Such as:
551
					 * <img src=' '
552
					 * But not:
553
					 * <img src='
554
					 * 
555
					 * </body>
556
					 * </html>
557
					 * In the latter case we only want to replace the opening text of the container
558
					 * Admittedly crude test, but effective.
559
					 */
560
					if(openRegion.getType() != closeRegion.getType()) {
561
						replaceLength = openRegion.getTextLength();
562
					}
563
				} 
564
565
				contentAssistRequest = new ContentAssistRequest(nodeAtOffset, node, sdRegion,
566
						completionRegion, sdRegion.getStartOffset(completionRegion),
567
						replaceLength, matchString);
568
569
				addAttributeValueProposals(contentAssistRequest, context);
570
			}
571
		}
572
		return contentAssistRequest;
573
	}
574
575
	private ContentAssistRequest computeContentProposals(String matchString, ITextRegion completionRegion,
576
			IDOMNode nodeAtOffset, IDOMNode node, CompletionProposalInvocationContext context) {
577
578
		int documentPosition = context.getInvocationOffset();
579
		ContentAssistRequest contentAssistRequest = null;
580
581
		// setup to add children at the content node's position
582
		contentAssistRequest = new ContentAssistRequest(nodeAtOffset, node, getStructuredDocumentRegion(documentPosition), completionRegion, documentPosition, 0, matchString);
583
		if ((node != null) && (node.getNodeType() == Node.DOCUMENT_NODE) && (((Document) node).getDoctype() == null)) {
584
			addStartDocumentProposals(contentAssistRequest, context);
585
		}
586
		addTagInsertionProposals(contentAssistRequest, getElementPosition(nodeAtOffset), context);
587
		if (node.getNodeType() != Node.DOCUMENT_NODE) {
588
			addEndTagProposals(contentAssistRequest, context);
589
		}
590
		// entities?
591
		addEntityProposals(contentAssistRequest, completionRegion, node, context);
592
		return contentAssistRequest;
593
	}
594
595
	private ContentAssistRequest computeEndTagOpenProposals(String matchString, ITextRegion completionRegion,
596
			IDOMNode nodeAtOffset, IDOMNode node, CompletionProposalInvocationContext context) {
597
598
		int documentPosition = context.getInvocationOffset();
599
		ContentAssistRequest contentAssistRequest = null;
600
		IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition);
601
		int completionRegionStart = sdRegion.getStartOffset(completionRegion);
602
		int completionRegionLength = completionRegion.getLength();
603
		IStructuredDocumentRegion sdRegionAtCompletionOffset = node.getStructuredDocument().getRegionAtCharacterOffset(completionRegionStart + completionRegionLength);
604
		ITextRegion regionAtEndOfCompletion = sdRegionAtCompletionOffset.getRegionAtCharacterOffset(completionRegionStart + completionRegionLength);
605
606
		if ((documentPosition != completionRegionStart) && (regionAtEndOfCompletion != null) && (regionAtEndOfCompletion.getType() == DOMRegionContext.XML_TAG_NAME)) {
607
			ITextRegion nameRegion = regionAtEndOfCompletion;
608
			contentAssistRequest = new ContentAssistRequest(nodeAtOffset, nodeAtOffset.getParentNode(), sdRegion, completionRegion, sdRegion.getStartOffset(nameRegion), nameRegion.getTextLength(), matchString);
609
		}
610
		else {
611
			if (nodeAtOffset.getFirstStructuredDocumentRegion() == sdRegion) {
612
				// abnormal case, this unmatched end tag will be a sibling
613
				contentAssistRequest = new ContentAssistRequest(nodeAtOffset, nodeAtOffset.getParentNode(), sdRegion, completionRegion, documentPosition, 0, matchString);
614
			}
615
			else {
616
				// normal case, this end tag is the parent
617
				contentAssistRequest = new ContentAssistRequest(nodeAtOffset, nodeAtOffset, sdRegion, completionRegion, documentPosition, 0, matchString);
618
			}
619
		}
620
		// if (documentPosition >= sdRegion.getStartOffset(completionRegion) +
621
		// completionRegion.getTextLength())
622
		addEndTagProposals(contentAssistRequest, context);
623
		// else
624
		if (completionRegionStart == documentPosition) {
625
			// positioned at start of end tag
626
			addTagInsertionProposals(contentAssistRequest, node.getChildNodes().getLength(), context);
627
		}
628
		return contentAssistRequest;
629
	}
630
631
632
	private ContentAssistRequest computeEqualsProposals(String matchString, ITextRegion completionRegion,
633
			IDOMNode nodeAtOffset, IDOMNode node, CompletionProposalInvocationContext context) {
634
635
		int documentPosition = context.getInvocationOffset();
636
		ContentAssistRequest contentAssistRequest = null;
637
		IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition);
638
		ITextRegion valueRegion = node.getStartStructuredDocumentRegion().getRegionAtCharacterOffset(sdRegion.getStartOffset(completionRegion) + completionRegion.getLength());
639
		if ((valueRegion != null) && (valueRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) && (sdRegion.getStartOffset(valueRegion) <= documentPosition)) {
640
			// replace the adjacent attribute value
641
			contentAssistRequest = new ContentAssistRequest(nodeAtOffset, node, sdRegion, valueRegion, sdRegion.getStartOffset(valueRegion), valueRegion.getTextLength(), matchString);
642
		}
643
		else {
644
			// append an attribute value after the '='
645
			contentAssistRequest = new ContentAssistRequest(nodeAtOffset, node, sdRegion, completionRegion, documentPosition, 0, matchString);
646
		}
647
		addAttributeValueProposals(contentAssistRequest, context);
648
		return contentAssistRequest;
649
	}
650
651
	private ContentAssistRequest computeStartDocumentProposals(String matchString, ITextRegion completionRegion,
652
			IDOMNode nodeAtOffset, IDOMNode node, CompletionProposalInvocationContext context) {
653
		int documentPosition = context.getInvocationOffset();
654
655
		// setup for a non-empty document, but one that hasn't been formally started
656
		ContentAssistRequest contentAssistRequest = null;
657
		contentAssistRequest = new ContentAssistRequest(nodeAtOffset, node,
658
				getStructuredDocumentRegion(documentPosition), completionRegion,
659
				documentPosition, 0, matchString);
660
		addStartDocumentProposals(contentAssistRequest, context);
661
		return contentAssistRequest;
662
	}
663
664
	private ContentAssistRequest computeTagCloseProposals(String matchString, ITextRegion completionRegion,
665
			IDOMNode nodeAtOffset, IDOMNode node, CompletionProposalInvocationContext context) {
666
667
		int documentPosition = context.getInvocationOffset();
668
		ContentAssistRequest contentAssistRequest = null;
669
		IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition);
670
671
		if ((node.getNodeType() == Node.DOCUMENT_NODE) || (documentPosition >= sdRegion.getEndOffset())) {
672
			// this is a content request as the documentPosition is 
673
			// AFTER the end of the closing region
674
			if ((node == nodeAtOffset) && (node.getParentNode() != null)) {
675
				node = (IDOMNode) node.getParentNode();
676
			}
677
			contentAssistRequest = new ContentAssistRequest(nodeAtOffset, node, sdRegion, completionRegion, documentPosition, 0, matchString);
678
			addTagInsertionProposals(contentAssistRequest, getElementPosition(nodeAtOffset), context);
679
			if ((node.getNodeType() != Node.DOCUMENT_NODE) && (node.getEndStructuredDocumentRegion() == null)) {
680
				addEndTagProposals(contentAssistRequest, context);
681
			}
682
		}
683
		else {
684
			// at the start of the tag's close or within it
685
			ITextRegion closeRegion = sdRegion.getLastRegion();
686
			boolean insideTag = !sdRegion.isEnded() || (documentPosition <= sdRegion.getStartOffset(closeRegion));
687
			if (insideTag) {
688
				// this is a request for completions within a tag
689
				contentAssistRequest = new ContentAssistRequest(nodeAtOffset, node, sdRegion, completionRegion, documentPosition, 0, matchString);
690
				if ((node.getNodeType() != Node.DOCUMENT_NODE) && (node.getEndStructuredDocumentRegion() != null)) {
691
					addTagCloseProposals(contentAssistRequest, context);
692
				}
693
				if (sdRegion == nodeAtOffset.getFirstStructuredDocumentRegion()) {
694
					contentAssistRequest.setReplacementBeginPosition(documentPosition);
695
					contentAssistRequest.setReplacementLength(0);
696
					addAttributeNameProposals(contentAssistRequest, context);
697
				}
698
			}
699
		}
700
		return contentAssistRequest;
701
	}
702
703
	private ContentAssistRequest computeTagNameProposals(String matchString, ITextRegion completionRegion,
704
			IDOMNode nodeAtOffset, IDOMNode node, CompletionProposalInvocationContext context) {
705
706
		int documentPosition = context.getInvocationOffset();
707
		ContentAssistRequest contentAssistRequest = null;
708
		IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition);
709
710
		if (sdRegion != nodeAtOffset.getFirstStructuredDocumentRegion()) {
711
			// completing the *first* tag in "<tagname1 |<tagname2"
712
			IDOMNode actualNode = (IDOMNode) node.getModel().getIndexedRegion(sdRegion.getStartOffset(completionRegion));
713
			if (actualNode != null) {
714
				if (actualNode.getFirstStructuredDocumentRegion() == sdRegion) {
715
					// start tag
716
					if (documentPosition > sdRegion.getStartOffset(completionRegion) + completionRegion.getLength()) {
717
						// it's attributes
718
						contentAssistRequest = new ContentAssistRequest(actualNode, actualNode, sdRegion, completionRegion, documentPosition - matchString.length(), matchString.length(), matchString);
719
						if (node.getStructuredDocument().getRegionAtCharacterOffset(sdRegion.getStartOffset(completionRegion) - 1).getRegionAtCharacterOffset(sdRegion.getStartOffset(completionRegion) - 1).getType() == DOMRegionContext.XML_TAG_OPEN) {
720
							addAttributeNameProposals(contentAssistRequest, context);
721
						}
722
						addTagCloseProposals(contentAssistRequest, context);
723
					}
724
					else {
725
						// it's name
726
						contentAssistRequest = new ContentAssistRequest(actualNode, actualNode.getParentNode(),
727
								sdRegion, completionRegion, documentPosition - matchString.length(),
728
								matchString.length(), matchString);
729
						addTagNameProposals(contentAssistRequest, getElementPosition(actualNode),
730
								context);
731
					}
732
				}
733
				else {
734
					if (documentPosition >= sdRegion.getStartOffset(completionRegion) + completionRegion.getLength()) {
735
						// insert name
736
						contentAssistRequest = new ContentAssistRequest(actualNode, actualNode.getParentNode(),
737
								sdRegion, completionRegion, documentPosition, 0, matchString);
738
					}
739
					else {
740
						// replace name
741
						contentAssistRequest = new ContentAssistRequest(actualNode, actualNode.getParentNode(),
742
								sdRegion, completionRegion, sdRegion.getStartOffset(completionRegion),
743
								completionRegion.getTextLength(), matchString);
744
					}
745
					addEndTagNameProposals(contentAssistRequest, context);
746
				}
747
			}
748
		}
749
		else {
750
			if (documentPosition > sdRegion.getStartOffset(completionRegion) + completionRegion.getTextLength()) {
751
				// unclosed tag with only a name; 
752
				//should prompt for attributes and a close instead
753
				contentAssistRequest = new ContentAssistRequest(nodeAtOffset, node, sdRegion, completionRegion,
754
						documentPosition - matchString.length(), matchString.length(), matchString);
755
				addAttributeNameProposals(contentAssistRequest, context);
756
				addTagCloseProposals(contentAssistRequest, context);
757
			}
758
			else {
759
				if (sdRegion.getRegions().get(0).getType() != DOMRegionContext.XML_END_TAG_OPEN) {
760
					int replaceLength = documentPosition - sdRegion.getStartOffset(completionRegion);
761
					contentAssistRequest = new ContentAssistRequest(node, node.getParentNode(), sdRegion,
762
							completionRegion, sdRegion.getStartOffset(completionRegion), replaceLength, matchString);
763
					addTagNameProposals(contentAssistRequest, getElementPosition(nodeAtOffset), context);
764
				}
765
				else {
766
					IDOMNode actualNode = (IDOMNode) node.getModel().getIndexedRegion(documentPosition);
767
					if (actualNode != null) {
768
						if (documentPosition >= sdRegion.getStartOffset(completionRegion) + completionRegion.getTextLength()) {
769
							contentAssistRequest = new ContentAssistRequest(actualNode, actualNode.getParentNode(),
770
									sdRegion, completionRegion, documentPosition, 0, matchString);
771
						}
772
						else {
773
							contentAssistRequest = new ContentAssistRequest(actualNode, actualNode.getParentNode(),
774
									sdRegion, completionRegion, sdRegion.getStartOffset(completionRegion),
775
									completionRegion.getTextLength(), matchString);
776
						}
777
						addEndTagNameProposals(contentAssistRequest, context);
778
					}
779
				}
780
			}
781
		}
782
		return contentAssistRequest;
783
	}
784
785
	private ContentAssistRequest computeTagOpenProposals(String matchString, ITextRegion completionRegion,
786
			IDOMNode nodeAtOffset, IDOMNode node, CompletionProposalInvocationContext context) {
787
788
		int documentPosition = context.getInvocationOffset();
789
		ContentAssistRequest contentAssistRequest = null;
790
		IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition);
791
		if (sdRegion != nodeAtOffset.getFirstStructuredDocumentRegion() || sdRegion.getPrevious() != null && sdRegion.getPrevious().getLastRegion().getType() == DOMRegionContext.XML_TAG_OPEN) {
792
			// completing the *first* XML_TAG_OPEN in "<<tagname"
793
			IDOMNode actualNode = (IDOMNode) node.getModel().getIndexedRegion(sdRegion.getStartOffset(completionRegion));
794
			if (actualNode != null) {
795
				if(sdRegion.getFirstRegion().getType() == DOMRegionContext.XML_END_TAG_OPEN) {
796
					contentAssistRequest = new ContentAssistRequest(actualNode, actualNode, sdRegion, completionRegion, documentPosition, 0, matchString);
797
					if(actualNode.hasChildNodes())
798
						addTagNameProposals(contentAssistRequest,
799
								getElementPosition(actualNode.getLastChild()), context);
800
					else
801
						addTagNameProposals(contentAssistRequest, 0, context);
802
				}
803
				else {
804
					contentAssistRequest = new ContentAssistRequest(actualNode, actualNode.getParentNode(), sdRegion, completionRegion, documentPosition, 0, matchString);
805
					addTagNameProposals(contentAssistRequest, getElementPosition(actualNode), context);
806
				}
807
				addEndTagProposals(contentAssistRequest, context); // (pa) 220850
808
			}
809
		}
810
		else {
811
			if (documentPosition == sdRegion.getStartOffset(completionRegion)) {
812
				if (node.getNodeType() == Node.ELEMENT_NODE) {
813
					// at the start of an existing tag, right before the '<'
814
					contentAssistRequest = new ContentAssistRequest(nodeAtOffset, node.getParentNode(), sdRegion,
815
							completionRegion, documentPosition, 0, matchString);
816
					addTagInsertionProposals(contentAssistRequest, getElementPosition(nodeAtOffset), context);
817
					addEndTagProposals(contentAssistRequest, context);
818
				}
819
				else if (node.getNodeType() == Node.DOCUMENT_NODE) {
820
					// at the opening of the VERY first tag with a '<'
821
					contentAssistRequest = new ContentAssistRequest(nodeAtOffset, node.getParentNode(), sdRegion,
822
							completionRegion, sdRegion.getStartOffset(completionRegion), completionRegion.getTextLength(), matchString);
823
					addStartDocumentProposals(contentAssistRequest, context);
824
				}
825
			}
826
			else {
827
				// within the white space
828
				ITextRegion name = getNameRegion(node.getStartStructuredDocumentRegion());
829
				if ((name != null) &&
830
						((sdRegion.getStartOffset(name) <= documentPosition) && (sdRegion.getEndOffset(name) >= documentPosition)) &&
831
						(sdRegion.getLastRegion().getType() == DOMRegionContext.XML_TAG_CLOSE || sdRegion.getLastRegion().getType() == DOMRegionContext.XML_EMPTY_TAG_CLOSE)){ 
832
833
					// replace the existing name
834
					contentAssistRequest = new ContentAssistRequest(node, node.getParentNode(), sdRegion, completionRegion, sdRegion.getStartOffset(name), name.getTextLength(), matchString);
835
				}
836
				else {
837
					// insert a valid new name, or possibly an end tag
838
					contentAssistRequest = new ContentAssistRequest(nodeAtOffset, ((Node) nodeAtOffset).getParentNode(), sdRegion, completionRegion, documentPosition, 0, matchString);
839
					addEndTagProposals(contentAssistRequest, context);
840
					contentAssistRequest.setReplacementBeginPosition(documentPosition);
841
					contentAssistRequest.setReplacementLength(0);
842
				}
843
				addTagNameProposals(contentAssistRequest, getElementPosition(nodeAtOffset), context);
844
			}
845
		}
846
		return contentAssistRequest;
847
	}
848
849
	private ITextRegion getCompletionRegion(int offset, IStructuredDocumentRegion sdRegion) {
850
		ITextRegion region = sdRegion.getRegionAtCharacterOffset(offset);
851
		if (region == null) {
852
			return null;
853
		}
854
855
		if (sdRegion.getStartOffset(region) == offset) {
856
			// The offset is at the beginning of the region
857
			if ((sdRegion.getStartOffset(region) == sdRegion.getStartOffset()) && (sdRegion.getPrevious() != null) && (!sdRegion.getPrevious().isEnded())) {
858
				// Is the region also the start of the node? If so, the
859
				// previous IStructuredDocumentRegion is
860
				// where to look for a useful region.
861
				region = sdRegion.getPrevious().getRegionAtCharacterOffset(offset - 1);
862
			}
863
			else {
864
				// Is there no separating whitespace from the previous region?
865
				// If not,
866
				// then that region is the important one
867
				ITextRegion previousRegion = sdRegion.getRegionAtCharacterOffset(offset - 1);
868
				if ((previousRegion != null) && (previousRegion != region) && (previousRegion.getTextLength() == previousRegion.getLength())) {
869
					region = previousRegion;
870
				}
871
			}
872
		}
873
		else {
874
			// The offset is NOT at the beginning of the region
875
			if (offset > sdRegion.getStartOffset(region) + region.getTextLength()) {
876
				// Is the offset within the whitespace after the text in this
877
				// region?
878
				// If so, use the next region
879
				ITextRegion nextRegion = sdRegion.getRegionAtCharacterOffset(sdRegion.getStartOffset(region) + region.getLength());
880
				if (nextRegion != null) {
881
					region = nextRegion;
882
				}
883
			}
884
			else {
885
				// Is the offset within the important text for this region?
886
				// If so, then we've already got the right one.
887
			}
888
		}
889
890
		// valid WHITE_SPACE region handler (#179924)
891
		if ((region != null) && (region.getType() == DOMRegionContext.WHITE_SPACE)) {
892
			ITextRegion previousRegion = sdRegion.getRegionAtCharacterOffset(sdRegion.getStartOffset(region) - 1);
893
			if (previousRegion != null) {
894
				region = previousRegion;
895
			}
896
		}
897
898
		return region;
899
	}
900
901
	/**
902
	 * Return the region whose content's require completion. This is something
903
	 * of a misnomer as sometimes the user wants to be prompted for contents
904
	 * of a non-existant ITextRegion, such as for enumerated attribute values
905
	 * following an '=' sign.
906
	 */
907
	private ITextRegion getCompletionRegion(int documentPosition, Node domnode) {
908
		if (domnode == null) {
909
			return null;
910
		}
911
912
		ITextRegion region = null;
913
		int offset = documentPosition;
914
		IStructuredDocumentRegion flatNode = null;
915
		IDOMNode node = (IDOMNode) domnode;
916
917
		if (node.getNodeType() == Node.DOCUMENT_NODE) {
918
			if (node.getStructuredDocument().getLength() == 0) {
919
				return null;
920
			}
921
			ITextRegion result = node.getStructuredDocument().getRegionAtCharacterOffset(offset).getRegionAtCharacterOffset(offset);
922
			while (result == null) {
923
				offset--;
924
				result = node.getStructuredDocument().getRegionAtCharacterOffset(offset).getRegionAtCharacterOffset(offset);
925
			}
926
			return result;
927
		}
928
929
		IStructuredDocumentRegion startTag = node.getStartStructuredDocumentRegion();
930
		IStructuredDocumentRegion endTag = node.getEndStructuredDocumentRegion();
931
932
		// Determine if the offset is within the start
933
		// IStructuredDocumentRegion, end IStructuredDocumentRegion, or
934
		// somewhere within the Node's XML content.
935
		if ((startTag != null) && (startTag.getStartOffset() <= offset) && (offset < startTag.getStartOffset() + startTag.getLength())) {
936
			flatNode = startTag;
937
		}
938
		else if ((endTag != null) && (endTag.getStartOffset() <= offset) && (offset < endTag.getStartOffset() + endTag.getLength())) {
939
			flatNode = endTag;
940
		}
941
942
		if (flatNode != null) {
943
			// the offset is definitely within the start or end tag, continue
944
			// on and find the region
945
			region = getCompletionRegion(offset, flatNode);
946
		}
947
		else {
948
			// the docPosition is neither within the start nor the end, so it
949
			// must be content
950
			flatNode = node.getStructuredDocument().getRegionAtCharacterOffset(offset);
951
			// (pa) ITextRegion refactor
952
			// if (flatNode.contains(documentPosition)) {
953
			if ((flatNode.getStartOffset() <= documentPosition) && (flatNode.getEndOffset() >= documentPosition)) {
954
				// we're interesting in completing/extending the previous
955
				// IStructuredDocumentRegion if the current
956
				// IStructuredDocumentRegion isn't plain content or if it's
957
				// preceded by an orphan '<'
958
				if ((offset == flatNode.getStartOffset()) &&
959
						(flatNode.getPrevious() != null) &&
960
						(((flatNode.getRegionAtCharacterOffset(documentPosition) != null) &&
961
								(flatNode.getRegionAtCharacterOffset(documentPosition).getType() != DOMRegionContext.XML_CONTENT)) ||
962
								(flatNode.getPrevious().getLastRegion().getType() == DOMRegionContext.XML_TAG_OPEN) ||
963
								(flatNode.getPrevious().getLastRegion().getType() == DOMRegionContext.XML_END_TAG_OPEN))) {
964
965
					// Is the region also the start of the node? If so, the
966
					// previous IStructuredDocumentRegion is
967
					// where to look for a useful region.
968
					region = flatNode.getPrevious().getLastRegion();
969
				}
970
				else if (flatNode.getEndOffset() == documentPosition) {
971
					region = flatNode.getLastRegion();
972
				}
973
				else {
974
					region = flatNode.getFirstRegion();
975
				}
976
			}
977
			else {
978
				// catch end of document positions where the docPosition isn't
979
				// in a IStructuredDocumentRegion
980
				region = flatNode.getLastRegion();
981
			}
982
		}
983
984
		return region;
985
	}
986
987
	private int getElementPosition(Node child) {
988
		Node parent = child.getParentNode();
989
		if (parent == null) {
990
			return 0;
991
		}
992
993
		NodeList children = parent.getChildNodes();
994
		if (children == null) {
995
			return 0;
996
		}
997
		int count = 0;
998
999
		for (int i = 0; i < children.getLength(); i++) {
1000
			if (children.item(i) == child) {
1001
				return count;
1002
			}
1003
			else {
1004
				// if (children.item(i).getNodeType() == Node.ELEMENT_NODE)
1005
				count++;
1006
			}
1007
		}
1008
		return 0;
1009
	}
1010
1011
	/**
1012
	 * the returned string will be used as the filter to show the proposed values
1013
	 * @throws BadLocationException 
1014
	 */
1015
	protected String getMatchString(IStructuredDocumentRegion parent, ITextRegion aRegion, int offset) throws BadLocationException {
1016
		if ((aRegion == null) || isCloseRegion(aRegion)) {
1017
			return ""; //$NON-NLS-1$
1018
		}
1019
		String matchString = null;
1020
		String regionType = aRegion.getType();
1021
		if ((regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) || (regionType == DOMRegionContext.XML_TAG_OPEN) || (offset > parent.getStartOffset(aRegion) + aRegion.getTextLength())) {
1022
			matchString = ""; //$NON-NLS-1$
1023
		}
1024
		else if (regionType == DOMRegionContext.XML_CONTENT || regionType == DOMRegionContext.XML_END_TAG_OPEN) {
1025
			int begin = parent.getPrevious().getStartOffset();
1026
			int length = offset-parent.getPrevious().getStart();
1027
			matchString = parent.getParentDocument().get(begin, length);
1028
1029
			// parent.getParentDocument().get(begin, length) could return
1030
			// something likes <schema> or <schema>a or <schema>  a
1031
			// get the substring as the match string
1032
			if ((matchString.length() > 0) && (beginsWith(matchString, "<"))) {
1033
				if (matchString.contains(">")) {
1034
					matchString = parent.getParentDocument().get(begin + matchString.indexOf('>') + 1, length-matchString.indexOf('>')-1);
1035
				} else {
1036
					matchString ="";
1037
				}
1038
			}
1039
1040
			// chop off any leading whitespace(s) from the match string
1041
			while ((matchString.length() > 0) && (Character.isWhitespace(matchString.charAt(0)))) { 
1042
				matchString = matchString.substring(1);
1043
			}
1044
		}
1045
		else {
1046
			if ((parent.getText(aRegion).length() > 0) && (parent.getStartOffset(aRegion) < offset)) {
1047
				matchString = parent.getText(aRegion).substring(0, offset - parent.getStartOffset(aRegion));
1048
			} else {
1049
				matchString = "";
1050
			}
1051
		}
1052
		return matchString;
1053
	}
1054
1055
	@SuppressWarnings("rawtypes")
1056
	private ITextRegion getNameRegion(IStructuredDocumentRegion flatNode) {
1057
		if (flatNode == null) {
1058
			return null;
1059
		}
1060
		Iterator regionList = flatNode.getRegions().iterator();
1061
		while (regionList.hasNext()) {
1062
			ITextRegion region = (ITextRegion) regionList.next();
1063
			if (isNameRegion(region)) {
1064
				return region;
1065
			}
1066
		}
1067
		return null;
1068
	}
1069
1070
	private boolean isCloseRegion(ITextRegion region) {
1071
		String type = region.getType();
1072
		return ((type == DOMRegionContext.XML_PI_CLOSE) ||
1073
				(type == DOMRegionContext.XML_TAG_CLOSE) ||
1074
				(type == DOMRegionContext.XML_EMPTY_TAG_CLOSE) ||
1075
				(type == DOMRegionContext.XML_CDATA_CLOSE) ||
1076
				(type == DOMRegionContext.XML_COMMENT_CLOSE) ||
1077
				(type == DOMRegionContext.XML_ATTLIST_DECL_CLOSE) ||
1078
				(type == DOMRegionContext.XML_ELEMENT_DECL_CLOSE) ||
1079
				(type == DOMRegionContext.XML_DOCTYPE_DECLARATION_CLOSE) ||
1080
				(type == DOMRegionContext.XML_DECLARATION_CLOSE));
1081
	}
1082
1083
	private boolean isNameRegion(ITextRegion region) {
1084
		String type = region.getType();
1085
		return ((type == DOMRegionContext.XML_TAG_NAME) ||
1086
				(type == DOMRegionContext.XML_ELEMENT_DECL_NAME) ||
1087
				(type == DOMRegionContext.XML_DOCTYPE_NAME) ||
1088
				(type == DOMRegionContext.XML_ATTLIST_DECL_NAME));
1089
	}
1090
1091
	/**
1092
	 * StructuredTextViewer must be set before using this.
1093
	 */
1094
	private IStructuredDocumentRegion getStructuredDocumentRegion(int pos) {
1095
		return ContentAssistUtils.getStructuredDocumentRegion(fTextViewer, pos);
1096
	}
1097
}
(-)src/org/eclipse/jpt/jpa/ui/internal/DefaultJpaXmlCompletionProposalComputer.java (+223 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2012 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     
11
 *******************************************************************************/
12
package org.eclipse.jpt.jpa.ui.internal;
13
14
import java.util.Properties;
15
import java.util.Vector;
16
17
import org.eclipse.jface.text.contentassist.ICompletionProposal;
18
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
19
import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
20
import org.eclipse.wst.sse.ui.contentassist.CompletionProposalInvocationContext;
21
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
22
import org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest;
23
24
/**
25
 * <p>Default implementation of the {@link AbstractJpaXmlCompletionProposalComputer}, defaults are to do nothing</p>
26
 *
27
 * The code of this class was copied from DefaultXMLCompletionProposalComputer and modified according to
28
 * the needs of the XML content assist of Dali.
29
 * 
30
 * The existence of this class is to isolate WTP code that will be removed after bug 371939 is addressed.
31
 * When it can be removed, we should try to eliminate the subclassing of this "default" implementation.
32
 */
33
34
public class DefaultJpaXmlCompletionProposalComputer extends
35
		AbstractJpaXmlCompletionProposalComputer {
36
37
	/**
38
	 * Default behavior is do to nothing.
39
	 * 
40
	 * @see org.eclipse.wst.sse.ui.contentassist.ICompletionProposalComputer#sessionEnded()
41
	 */
42
	public void sessionEnded() {
43
		//default behavior is to do nothing
44
	}
45
46
	/**
47
	 * Default behavior is do to nothing.
48
	 * 
49
	 * @see org.eclipse.wst.sse.ui.contentassist.ICompletionProposalComputer#sessionStarted()
50
	 */
51
	public void sessionStarted() {
52
		//default behavior is to do nothing
53
	}
54
	
55
	/**
56
	 * Default behavior is do to nothing.
57
	 * 
58
	 * @see org.eclipse.wst.xml.ui.internal.contentassist.AbstractXMLCompletionProposalComputer#addAttributeNameProposals(org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest, org.eclipse.wst.sse.ui.contentassist.CompletionProposalInvocationContext)
59
	 */
60
	@Override
61
	protected void addAttributeNameProposals(
62
			ContentAssistRequest contentAssistRequest,
63
			CompletionProposalInvocationContext context) {
64
		//default behavior is to do nothing
65
	}
66
67
	/**
68
	 * Default behavior is do to nothing.
69
	 * 
70
	 * @see org.eclipse.wst.xml.ui.internal.contentassist.AbstractXMLCompletionProposalComputer#addAttributeValueProposals(org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest, org.eclipse.wst.sse.ui.contentassist.CompletionProposalInvocationContext)
71
	 */
72
	@Override
73
	protected void addAttributeValueProposals(
74
			ContentAssistRequest contentAssistRequest,
75
			CompletionProposalInvocationContext context) {
76
		//default behavior is to do nothing
77
	}
78
79
	/**
80
	 * Default behavior is do to nothing.
81
	 * 
82
	 * @see org.eclipse.wst.xml.ui.internal.contentassist.AbstractXMLCompletionProposalComputer#addCommentProposal(org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest, org.eclipse.wst.sse.ui.contentassist.CompletionProposalInvocationContext)
83
	 */
84
	@Override
85
	protected void addCommentProposal(
86
			ContentAssistRequest contentAssistRequest,
87
			CompletionProposalInvocationContext context) {
88
		//default behavior is to do nothing
89
	}
90
91
	/**
92
	 * Default behavior is do to nothing.
93
	 * 
94
	 * @see org.eclipse.wst.xml.ui.internal.contentassist.AbstractXMLCompletionProposalComputer#addDocTypeProposal(org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest, org.eclipse.wst.sse.ui.contentassist.CompletionProposalInvocationContext)
95
	 */
96
	protected void addDocTypeProposal(
97
			ContentAssistRequest contentAssistRequest,
98
			CompletionProposalInvocationContext context) {
99
		//default behavior is to do nothing
100
	}
101
102
	/**
103
	 * Default behavior is do to nothing.
104
	 * 
105
	 * @see org.eclipse.wst.xml.ui.internal.contentassist.AbstractXMLCompletionProposalComputer#addEmptyDocumentProposals(org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest, org.eclipse.wst.sse.ui.contentassist.CompletionProposalInvocationContext)
106
	 */
107
	@Override
108
	protected void addEmptyDocumentProposals(
109
			ContentAssistRequest contentAssistRequest,
110
			CompletionProposalInvocationContext context) {
111
		//default behavior is to do nothing
112
	}
113
114
	/**
115
	 * Default behavior is do to nothing.
116
	 * 
117
	 * @see org.eclipse.wst.xml.ui.internal.contentassist.AbstractXMLCompletionProposalComputer#addEndTagNameProposals(org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest, org.eclipse.wst.sse.ui.contentassist.CompletionProposalInvocationContext)
118
	 */
119
	@Override
120
	protected void addEndTagNameProposals(
121
			ContentAssistRequest contentAssistRequest,
122
			CompletionProposalInvocationContext context) {
123
		//default behavior is to do nothing
124
	}
125
126
	/**
127
	 * Default behavior is do to nothing.
128
	 * 
129
	 * @see org.eclipse.wst.xml.ui.internal.contentassist.AbstractXMLCompletionProposalComputer#addEndTagProposals(org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest, org.eclipse.wst.sse.ui.contentassist.CompletionProposalInvocationContext)
130
	 */
131
	@Override
132
	protected void addEndTagProposals(
133
			ContentAssistRequest contentAssistRequest,
134
			CompletionProposalInvocationContext context) {
135
		//default behavior is to do nothing
136
	}
137
138
	/**
139
	 * Default behavior is do to nothing.
140
	 * 
141
	 * @see org.eclipse.wst.xml.ui.internal.contentassist.AbstractXMLCompletionProposalComputer#addEntityProposals(org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest, org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion, org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode, org.eclipse.wst.sse.ui.contentassist.CompletionProposalInvocationContext)
142
	 */
143
	@Override
144
	protected void addEntityProposals(
145
			ContentAssistRequest contentAssistRequest,
146
			ITextRegion completionRegion, IDOMNode treeNode,
147
			CompletionProposalInvocationContext context) {
148
		//default behavior is to do nothing
149
	}
150
151
	/**
152
	 * Default behavior is do to nothing.
153
	 * 
154
	 * @see org.eclipse.wst.xml.ui.internal.contentassist.AbstractXMLCompletionProposalComputer#addEntityProposals(java.util.Vector, java.util.Properties, java.lang.String, int, org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion, org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion, org.eclipse.wst.sse.ui.contentassist.CompletionProposalInvocationContext)
155
	 */
156
	@Override
157
	protected void addEntityProposals(Vector<ICompletionProposal> proposals, Properties map,
158
			String key, int nodeOffset, IStructuredDocumentRegion sdRegion,
159
			ITextRegion completionRegion,
160
			CompletionProposalInvocationContext context) {
161
		//default behavior is to do nothing
162
	}
163
164
	/**
165
	 * Default behavior is do to nothing.
166
	 * 
167
	 * @see org.eclipse.wst.xml.ui.internal.contentassist.AbstractXMLCompletionProposalComputer#addPCDATAProposal(java.lang.String, org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest, org.eclipse.wst.sse.ui.contentassist.CompletionProposalInvocationContext)
168
	 */
169
	@Override
170
	protected void addPCDATAProposal(String nodeName,
171
			ContentAssistRequest contentAssistRequest,
172
			CompletionProposalInvocationContext context) {
173
		//default behavior is to do nothing
174
	}
175
176
	/**
177
	 * Default behavior is do to nothing.
178
	 * 
179
	 * @see org.eclipse.wst.xml.ui.internal.contentassist.AbstractXMLCompletionProposalComputer#addStartDocumentProposals(org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest, org.eclipse.wst.sse.ui.contentassist.CompletionProposalInvocationContext)
180
	 */
181
	@Override
182
	protected void addStartDocumentProposals(
183
			ContentAssistRequest contentAssistRequest,
184
			CompletionProposalInvocationContext context) {
185
		//default behavior is to do nothing
186
	}
187
188
	/**
189
	 * Default behavior is do to nothing.
190
	 * 
191
	 * @see org.eclipse.wst.xml.ui.internal.contentassist.AbstractXMLCompletionProposalComputer#addTagCloseProposals(org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest, org.eclipse.wst.sse.ui.contentassist.CompletionProposalInvocationContext)
192
	 */
193
	@Override
194
	protected void addTagCloseProposals(
195
			ContentAssistRequest contentAssistRequest,
196
			CompletionProposalInvocationContext context) {
197
		//default behavior is to do nothing
198
	}
199
200
	/**
201
	 * Default behavior is do to nothing.
202
	 * 
203
	 * @see org.eclipse.wst.xml.ui.internal.contentassist.AbstractXMLCompletionProposalComputer#addTagInsertionProposals(org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest, int, org.eclipse.wst.sse.ui.contentassist.CompletionProposalInvocationContext)
204
	 */
205
	@Override
206
	protected void addTagInsertionProposals(
207
			ContentAssistRequest contentAssistRequest, int childPosition,
208
			CompletionProposalInvocationContext context) {
209
		//default behavior is to do nothing
210
	}
211
212
	/**
213
	 * Default behavior is do to nothing.
214
	 * 
215
	 * @see org.eclipse.wst.xml.ui.internal.contentassist.AbstractXMLCompletionProposalComputer#addTagNameProposals(org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest, int, org.eclipse.wst.sse.ui.contentassist.CompletionProposalInvocationContext)
216
	 */
217
	@Override
218
	protected void addTagNameProposals(
219
			ContentAssistRequest contentAssistRequest, int childPosition,
220
			CompletionProposalInvocationContext context) {
221
		//default behavior is to do nothing
222
	}
223
}
(-)src/org/eclipse/jpt/jpa/ui/internal/JpaXmlCompletionProposalComputer.java (+259 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2012 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;
15
16
/**
17
 * This computer adds content assist support for a mapping file (ORM Configuration).
18
 *
19
 * @version 2.3
20
 * @since 2.3
21
 */
22
23
import java.util.ArrayList;
24
import java.util.Collection;
25
import java.util.Collections;
26
import java.util.List;
27
import org.eclipse.core.filebuffers.FileBuffers;
28
import org.eclipse.core.filebuffers.ITextFileBuffer;
29
import org.eclipse.core.filebuffers.ITextFileBufferManager;
30
import org.eclipse.core.resources.IFile;
31
import org.eclipse.core.resources.IWorkspaceRoot;
32
import org.eclipse.core.resources.ResourcesPlugin;
33
import org.eclipse.core.runtime.IProgressMonitor;
34
import org.eclipse.jface.text.contentassist.CompletionProposal;
35
import org.eclipse.jface.text.contentassist.ICompletionProposal;
36
import org.eclipse.jpt.common.utility.internal.CollectionTools;
37
import org.eclipse.jpt.common.utility.internal.StringTools;
38
import org.eclipse.jpt.jpa.core.JpaFile;
39
import org.eclipse.jpt.jpa.core.JpaStructureNode;
40
import org.eclipse.jpt.jpa.core.JpaXmlStructureNode;
41
import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
42
import org.eclipse.wst.sse.ui.contentassist.CompletionProposalInvocationContext;
43
import org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal;
44
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
45
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
46
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
47
import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
48
import org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest;
49
import org.eclipse.wst.xml.ui.internal.contentassist.XMLRelevanceConstants;
50
import org.w3c.dom.Document;
51
import org.w3c.dom.Node;
52
53
public class JpaXmlCompletionProposalComputer extends DefaultJpaXmlCompletionProposalComputer {
54
55
	public JpaXmlCompletionProposalComputer() {
56
	}
57
58
		@Override
59
		public List<ICompletionProposal> computeCompletionProposals(
60
				CompletionProposalInvocationContext context,
61
				IProgressMonitor monitor) {
62
			try {
63
				return super.computeCompletionProposals(context, monitor);
64
			} catch (RuntimeException ex) {
65
				// When we run into any unexpected exception, we will log the exception
66
				// and then return an empty list to prevent code completion process from 
67
				// crashing. We need to determine if runtime exceptions should be 
68
				// expected. If so, we could remove the log(ex) in the future.
69
				JptJpaUiPlugin.log(ex);
70
				return Collections.emptyList();
71
			}
72
		}
73
74
	@Override
75
	protected void addAttributeValueProposals(ContentAssistRequest contentAssistRequest,
76
			CompletionProposalInvocationContext context) {
77
78
		List<String> proposedValues = getProposedValues(context);
79
80
		if (proposedValues.size() > 0 ) {
81
			String matchString = contentAssistRequest.getMatchString();
82
			if (matchString == null) {
83
				matchString = ""; //$NON-NLS-1$
84
			}
85
			if ((matchString.length() > 0) && (matchString.startsWith("\"") || matchString.startsWith("'"))) { //$NON-NLS-1$ //$NON-NLS-2$
86
				matchString = matchString.substring(1);
87
			}
88
			//create suggestions for this attribute value declaration
89
			int rOffset = contentAssistRequest.getReplacementBeginPosition();
90
			int rLength = contentAssistRequest.getReplacementLength();
91
			for (String possibleValue : proposedValues) {
92
				if ((matchString.length() == 0) || StringTools.stringStartsWithIgnoreCase(possibleValue, matchString)) {
93
					String rString = "\"" + possibleValue + "\""; //$NON-NLS-1$ //$NON-NLS-2$
94
					CompletionProposal proposal = new CompletionProposal(
95
							rString, rOffset, rLength, rString.length());
96
					contentAssistRequest.addProposal(proposal);
97
				}
98
			}
99
		}
100
		else {
101
			setErrorMessage(XMLUIMessages.Content_Assist_not_availab_UI_);
102
		}
103
	}
104
105
	@SuppressWarnings("deprecation")
106
	@Override
107
	protected void addTagInsertionProposals(
108
			ContentAssistRequest contentAssistRequest, int childPosition,
109
			CompletionProposalInvocationContext context) {
110
111
		Node parent = contentAssistRequest.getParent();
112
113
		// This is only valid at the document element level
114
		// and only valid if it's a XML file
115
		if ((parent != null) && (parent.getNodeType() == Node.DOCUMENT_NODE) &&
116
				((IDOMDocument) parent).isXMLType() && !isCursorAfterXMLPI(contentAssistRequest)) {
117
			return;
118
		}
119
		// only want completion proposals if cursor is after doctype...
120
		if (!isCursorAfterDoctype(contentAssistRequest)) {
121
			return;
122
		}
123
124
		if ((parent != null) && (parent instanceof IDOMNode) && isCommentNode((IDOMNode) parent)) {
125
			// loop and find non comment node?
126
			while ((parent != null) && isCommentNode((IDOMNode) parent)) {
127
				parent = parent.getParentNode();
128
			}
129
		}
130
131
		List<String> proposedValues = getProposedValues(context);
132
133
		if (proposedValues.size() > 0 ) {
134
			String matchString = contentAssistRequest.getMatchString();
135
			if (matchString == null) {
136
				matchString = ""; //$NON-NLS-1$
137
			}
138
139
			int begin = contentAssistRequest.getReplacementBeginPosition();
140
			int length = contentAssistRequest.getReplacementLength();
141
			if ((parent instanceof IDOMNode) && (parent.getNodeType() == Node.ELEMENT_NODE)) {
142
				if (((IDOMNode) parent).getLastStructuredDocumentRegion() != ((IDOMNode) parent).getFirstStructuredDocumentRegion()) {
143
					begin = ((IDOMNode) parent).getFirstStructuredDocumentRegion().getEndOffset();
144
					length = ((IDOMNode) parent).getLastStructuredDocumentRegion().getStartOffset() - begin;
145
				}
146
			}
147
148
			for (String possibleValue : proposedValues) {
149
				if ((matchString.length() == 0) || StringTools.stringStartsWithIgnoreCase(possibleValue, matchString)) {
150
					CustomCompletionProposal proposal = new CustomCompletionProposal(
151
							possibleValue, begin, length, possibleValue.length(), 
152
							JptJpaUiPlugin.getImage(JptUiIcons.JPA_CONTENT), 
153
							possibleValue, null, null, XMLRelevanceConstants.R_TAG_INSERTION);
154
					contentAssistRequest.addProposal(proposal);
155
				}
156
			}
157
		}
158
		else {
159
			setErrorMessage(XMLUIMessages.Content_Assist_not_availab_UI_);
160
		}
161
	}
162
	
163
	/**
164
	 * Retrieves all of the possible valid values for this attribute/element declaration
165
	 */
166
	private List<String> getProposedValues(CompletionProposalInvocationContext context) {
167
		List<String> list = new ArrayList<String>();
168
		int documentPosition = context.getInvocationOffset();
169
		if (documentPosition == -1) return Collections.emptyList();
170
171
		ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
172
		ITextFileBuffer buffer = manager.getTextFileBuffer(context.getDocument());
173
		if (buffer == null) return Collections.emptyList();
174
175
		IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
176
		IFile file = root.getFile(buffer.getLocation());
177
178
		JpaFile jpaFile = (JpaFile) file.getAdapter(JpaFile.class);
179
		if (jpaFile == null) return Collections.emptyList();
180
181
		Collection<JpaStructureNode> rootStructureNodes = CollectionTools.collection(jpaFile.getRootStructureNodes());
182
		if (rootStructureNodes.isEmpty()) {
183
			return Collections.emptyList();
184
		}
185
186
		for (JpaStructureNode node : rootStructureNodes) {
187
			Iterable<String> strings = ((JpaXmlStructureNode) node).getXmlCompletionProposals(documentPosition);
188
			if (strings != null) {
189
				CollectionTools.addAll(list, strings);
190
			} else {
191
				return Collections.emptyList();
192
			}
193
194
		}
195
		return list;
196
	}
197
198
	/**
199
	 * This method can check if the cursor is after the XMLPI
200
	 * 
201
	 * @param ContentAssistRequest car
202
	 */
203
	protected boolean isCursorAfterXMLPI(ContentAssistRequest car) {
204
		Node aNode = car.getNode();
205
		boolean xmlpiFound = false;
206
		Document parent = aNode.getOwnerDocument();
207
		int xmlpiNodePosition = -1;
208
		boolean isAfterXMLPI = false;
209
210
		if (parent == null) {
211
			return true; // blank document case
212
		}
213
214
		for (Node child = parent.getFirstChild(); child != null; child = child.getNextSibling()) {
215
			boolean xmlpi = ((child.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) && child.getNodeName().equals("xml")); //$NON-NLS-1$
216
			xmlpiFound = xmlpiFound || xmlpi;
217
			if (xmlpiFound) {
218
				if (child instanceof IDOMNode) {
219
					xmlpiNodePosition = ((IDOMNode) child).getEndOffset();
220
					isAfterXMLPI = (car.getReplacementBeginPosition() >= xmlpiNodePosition);
221
				}
222
				break;
223
			}
224
		}
225
		return isAfterXMLPI;
226
	}
227
228
	private boolean isCursorAfterDoctype(ContentAssistRequest car) {
229
		Node aNode = car.getNode();
230
		Document parent = aNode.getOwnerDocument();
231
		int xmldoctypeNodePosition = -1;
232
		boolean isAfterDoctype = true;
233
234
		if (parent == null) {
235
			return true; // blank document case
236
		}
237
238
		for (Node child = parent.getFirstChild(); child != null; child = child.getNextSibling()) {
239
			if (child instanceof IDOMNode) {
240
				if (child.getNodeType() == Node.DOCUMENT_TYPE_NODE) {
241
					xmldoctypeNodePosition = ((IDOMNode) child).getEndOffset();
242
					isAfterDoctype = (car.getReplacementBeginPosition() >= xmldoctypeNodePosition);
243
					break;
244
				}
245
			}
246
		}
247
		return isAfterDoctype;
248
	}
249
250
	/**
251
	 * This is to determine if a tag is a special meta-info comment tag that
252
	 * shows up as an ELEMENT
253
	 * 
254
	 * @param node
255
	 */
256
	private boolean isCommentNode(IDOMNode node) {
257
		return ((node != null) && (node instanceof IDOMElement) && ((IDOMElement) node).isCommentTag());
258
	}
259
}

Return to bug 188940