Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

teiiddes-1387: #204

Merged
merged 1 commit into from
Jul 15, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Platform;
Expand Down Expand Up @@ -2255,4 +2256,30 @@ public static IQueryService getTeiidQueryService() {
throw new RuntimeException(ex);
}
}

/**
* This method will generate a ModelResource based on IPath and and name
* @param location
* @param modelName
* @return
* @since 8.2
*/
public static ModelResource createModelResource(IPath location, String modelName) {
IResource resource;
IProject project;
resource = ModelerCore.getWorkspace().getRoot().findMember(location);

if( location.segmentCount() == 1 ) {
//We already have the project
project = (IProject)resource;
} else {
//Get the project for a folder(s)
project = resource.getProject();
}

IPath relativeModelPath = resource.getFullPath().removeFirstSegments(1).append(modelName);
final IFile modelFile = project.getFile( relativeModelPath );
final ModelResource resrc = ModelerCore.create( modelFile );
return resrc;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,7 @@ private RelationalModelExtensionAssistant getExtensionAssistant() {
* @throws ModelWorkspaceException if error creating model
*/
public ModelResource createRelationalModel( IPath location, String modelName) throws ModelWorkspaceException {
ModelWorkspaceItem mwItem = null;
if( location.segmentCount() == 1 ) {
// Project for ONE segment
mwItem = ModelWorkspaceManager.getModelWorkspaceManager().findModelWorkspaceItem(location.makeAbsolute(), IResource.PROJECT);
} else {
mwItem = ModelWorkspaceManager.getModelWorkspaceManager().findModelWorkspaceItem(location.makeAbsolute(), IResource.FOLDER);
}

IProject project = mwItem.getResource().getProject();
IPath relativeModelPath = mwItem.getPath().removeFirstSegments(1).append(modelName);
final IFile modelFile = project.getFile( relativeModelPath );
final ModelResource resrc = ModelerCore.create( modelFile );
final ModelResource resrc = ModelerCore.createModelResource(location, modelName);
resrc.getModelAnnotation().setPrimaryMetamodelUri( RELATIONAL_PACKAGE_URI );
resrc.getModelAnnotation().setModelType(ModelType.PHYSICAL_LITERAL);
ModelerCore.getModelEditor().getAllContainers(resrc.getEmfResource());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,14 @@ public ModelResource createModel(IPath location, String modelName) throws Modele
}

public ModelResource createRelationalModel( IPath location, String modelName) throws ModelWorkspaceException {
ModelWorkspaceItem mwItem = null;
if( location.segmentCount() == 1 ) {
// Project for ONE segment
mwItem = ModelWorkspaceManager.getModelWorkspaceManager().findModelWorkspaceItem(location.makeAbsolute(), IResource.PROJECT);
} else {
mwItem = ModelWorkspaceManager.getModelWorkspaceManager().findModelWorkspaceItem(location.makeAbsolute(), IResource.FOLDER);
}

IProject project = mwItem.getResource().getProject();
IPath relativeModelPath = mwItem.getPath().removeFirstSegments(1).append(modelName);
final IFile modelFile = project.getFile( relativeModelPath );
final ModelResource resrc = ModelerCore.create( modelFile );
final ModelResource resrc = ModelerCore.createModelResource(location, modelName);
resrc.getModelAnnotation().setPrimaryMetamodelUri( RELATIONAL_PACKAGE_URI );
resrc.getModelAnnotation().setModelType(ModelType.PHYSICAL_LITERAL);
ModelUtilities.initializeModelContainers(resrc, "Create Model Containers", this); //$NON-NLS-1$

return resrc;
}

public boolean addMissingProcedure(ModelResource modelResource, String specificProcedure) throws ModelerCoreException{
if( modelResource != null ) {
if( specificProcedure.equalsIgnoreCase(ALL_PROCEDURES)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,7 @@ public class FlatFileViewModelFactory extends FlatFileRelationalModelFactory {
public static final DatatypeManager datatypeManager = ModelerCore.getWorkspaceDatatypeManager();

public ModelResource createViewRelationalModel( IPath location, String modelName) throws ModelWorkspaceException {
ModelWorkspaceItem mwItem = null;

// One Segment -- Project
if( location.segmentCount() == 1 ) {
mwItem = ModelWorkspaceManager.getModelWorkspaceManager().findModelWorkspaceItem(location.makeAbsolute(), IResource.PROJECT);
} else {
// Multiple Segments -- Folder
mwItem = ModelWorkspaceManager.getModelWorkspaceManager().findModelWorkspaceItem(location.makeAbsolute(), IResource.FOLDER);
}

// Get the Project
IProject project = mwItem.getResource().getProject();

// Create the model at the specified relative path
IPath relativeModelPath = mwItem.getPath().removeFirstSegments(1).append(modelName);
final IFile modelFile = project.getFile( relativeModelPath );
final ModelResource resrc = ModelerCore.create( modelFile );
final ModelResource resrc = ModelerCore.createModelResource(location, modelName);
resrc.getModelAnnotation().setPrimaryMetamodelUri( RELATIONAL_PACKAGE_URI );
resrc.getModelAnnotation().setModelType(ModelType.VIRTUAL_LITERAL);
ModelUtilities.initializeModelContainers(resrc, "Create Model Containers", this); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,7 @@ public class XmlFileViewModelFactory extends FlatFileRelationalModelFactory {
public static final String WIDTH = "width"; //$NON-NLS-1$

public ModelResource createViewRelationalModel( IPath location, String modelName) throws ModelWorkspaceException {
ModelWorkspaceItem mwItem = null;

// One Segment -- Project
if( location.segmentCount() == 1 ) {
mwItem = ModelWorkspaceManager.getModelWorkspaceManager().findModelWorkspaceItem(location.makeAbsolute(), IResource.PROJECT);
} else {
// Multiple Segments -- Folder
mwItem = ModelWorkspaceManager.getModelWorkspaceManager().findModelWorkspaceItem(location.makeAbsolute(), IResource.FOLDER);
}

// Get the Project
IProject project = mwItem.getResource().getProject();

// Create the model at the specified relative path
IPath relativeModelPath = mwItem.getPath().removeFirstSegments(1).append(modelName);
final IFile modelFile = project.getFile( relativeModelPath );
final ModelResource resrc = ModelerCore.create( modelFile );
final ModelResource resrc = ModelerCore.createModelResource(location, modelName);
resrc.getModelAnnotation().setPrimaryMetamodelUri( RELATIONAL_PACKAGE_URI );
resrc.getModelAnnotation().setModelType(ModelType.VIRTUAL_LITERAL);
ModelUtilities.initializeModelContainers(resrc, "Create Model Containers", this); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,7 @@ public RelationalViewModelFactory() {
* @throws ModelWorkspaceException error thrown when problem creating new model
*/
public ModelResource createRelationalViewModel( IPath location, String modelName) throws ModelWorkspaceException {
ModelWorkspaceItem mwItem = null;
if( location.segmentCount() == 1 ) {
// Project for ONE segment
mwItem = ModelWorkspaceManager.getModelWorkspaceManager().findModelWorkspaceItem(location.makeAbsolute(), IResource.PROJECT);
} else {
mwItem = ModelWorkspaceManager.getModelWorkspaceManager().findModelWorkspaceItem(location.makeAbsolute(), IResource.FOLDER);
}

IProject project = mwItem.getResource().getProject();
IPath relativeModelPath = mwItem.getPath().removeFirstSegments(1).append(modelName);
final IFile modelFile = project.getFile( relativeModelPath );
final ModelResource resrc = ModelerCore.create( modelFile );
final ModelResource resrc = ModelerCore.createModelResource(location, modelName);
resrc.getModelAnnotation().setPrimaryMetamodelUri( RELATIONAL_PACKAGE_URI );
resrc.getModelAnnotation().setModelType(ModelType.VIRTUAL_LITERAL);
ModelerCore.getModelEditor().getAllContainers(resrc.getEmfResource());
Expand Down