コード例 #1
0
 /**
  * Used to find a resource using a relative URI referenced to a known resource
  *
  * @see
  *     org.teiid.designer.core.container.ResourceFinder#findByWorkspaceUri(org.eclipse.emf.common.util.URI,
  *     org.eclipse.emf.ecore.resource.Resource)
  * @since 5.0.2
  */
 @Override
 public Resource findByWorkspaceUri(final URI theRelativeUri, final Resource knownResource) {
   try {
     // Defect 23396 - an NPE was thrown here because a relativeUri was provide (i.e.
     // BooksDatatypes.xsd) which resulted
     // in a NULL model Resource or null corresponding resource.
     ModelResource mr = ModelerCore.getModelEditor().findModelResource(knownResource);
     if (mr != null && mr.getCorrespondingResource() != null) {
       IPath thePath =
           mr.getCorrespondingResource()
               .getFullPath()
               .removeLastSegments(1)
               .append(theRelativeUri.toString());
       IResource iResrc = ModelerCore.getWorkspace().getRoot().findMember(thePath);
       if (iResrc instanceof IFile) {
         ModelResource modelResource =
             ModelerCore.getModelEditor().findModelResource((IFile) iResrc);
         if (modelResource != null) {
           return modelResource.getEmfResource();
         }
       }
     }
   } catch (ModelWorkspaceException theException) {
     ModelerCore.Util.log(theException);
   }
   return null;
 }
コード例 #2
0
  /**
   * @see
   *     org.teiid.designer.core.container.ResourceFinder#findMissingImportLocations(org.eclipse.emf.ecore.resource.Resource)
   * @since 5.0.2
   */
  @Override
  public String[] findMissingImportLocations(final Resource theResource) {
    final Collection result = new HashSet();
    if (theResource != null && theResource instanceof MMXmiResource) {

      // just get the Resolved external resources (i.e. desired imports)
      Collection unresolvedResources = getResolvedExternalResources(theResource);

      // For each unresolved resource, create a location and check existing imports for this
      // location.
      for (Iterator iter = unresolvedResources.iterator(); iter.hasNext(); ) {
        Resource nextRes = (Resource) iter.next();

        String location =
            ModelerCore.getModelEditor().createModelLocation((MMXmiResource) theResource, nextRes);

        if (location != null) {
          ModelImport existingImport =
              ModelerCore.getModelEditor()
                  .getExistingModelImportForLocation((MMXmiResource) theResource, location);
          // If no existing import, add location to result
          if (existingImport == null) {
            result.add(location);
          }
        }
      }
    }
    return (String[]) result.toArray(new String[result.size()]);
  }
コード例 #3
0
  public static QueryMetadataContext buildQueryMetadataContext(
      final EObject eObject, final boolean restrictSearch) {
    Collection resources = null;
    Container container = null;
    try {
      // assume model container...modler metadata is for workspace
      container = ModelerCore.getModelContainer();
      ModelWorkspace workspace = ModelerCore.getModelWorkspace();
      if (workspace.isOpen()) {
        resources = Arrays.asList(workspace.getEmfResources());
      } else {
        resources = container.getResources();
      }
    } catch (CoreException e) {
      TransformationPlugin.Util.log(e);
    }

    // find the resoucre for the eObject in the container
    Resource resource = ModelerCore.getModelEditor().findResource(container, eObject);
    // create a indexSelector for this resource and instantiate transformation validator
    ModelResourceIndexSelector selector = new ModelResourceIndexSelector(resource);
    QueryMetadataContext context = new QueryMetadataContext(selector);
    // set the resource scope (all model resources in open model projects)
    context.setResources(resources);
    // set the restrict search flag
    context.setRestrictedSearch(restrictSearch);
    return context;
  }
コード例 #4
0
  /**
   * Returns true if the specified URI string is one of the well-known Teiid Designer/EMF
   * identifiers to a global resource such as
   *
   * <p>"http://www.metamatrix.com/metamodels/SimpleDatatypes-instance"
   * "http://www.metamatrix.com/metamodels/UmlPrimitiveTypes-instance"
   * "http://www.metamatrix.com/relationships/BuiltInRelationshipTypes-instance"
   * "http://www.w3.org/2001/XMLSchema" "http://www.w3.org/2001/MagicXMLSchema"
   * "http://www.w3.org/2001/XMLSchema-instance" otherwise false is returned.
   *
   * @param uri the URI string
   */
  public static boolean isGlobalResource(final String uri) {
    if (uri == null) return false;

    // http://www.w3.org/2001/xml.xsd
    //       "http://www.w3.org/2001/XMLSchema"; //$NON-NLS-1$
    //       "http://www.w3.org/2001/MagicXMLSchema"; //$NON-NLS-1$
    //       "http://www.w3.org/2001/XMLSchema-instance"; //$NON-NLS-1$

    // If the URI is to the Teiid Designer built-in datatypes model ...
    if (uri.startsWith(DatatypeConstants.BUILTIN_DATATYPES_URI)) return true;
    if (uri.endsWith(DatatypeConstants.DATATYPES_MODEL_FILE_NAME)) return true;

    // If the URI is to the Teiid Designer built-in UML primitive types model ...
    if (uri.startsWith(UML_PRIMITIVE_TYPES_INTERNAL_URI)) return true;
    if (uri.endsWith(UML_PRIMITIVE_TYPES_MODEL_FILE_NAME)) return true;
    if (uri.startsWith(UML_METAMODEL_URI)) return true;

    // If the URI is to the Teiid Designer built-in relationship model ...
    if (uri.endsWith(RELATIONSHIP_PRIMITIVE_TYPES_INTERNAL_URI)) return true;
    if (uri.endsWith(RELATIONSHIP_PRIMITIVE_TYPES_MODEL_FILE_NAME)) return true;

    // If the URI is to one of the Emf XMLSchema resources ...
    if (uri.startsWith(ModelerCore.XML_SCHEMA_INSTANCE_GENERAL_URI)
        || uri.startsWith(ModelerCore.XML_MAGIC_SCHEMA_GENERAL_URI)
        || uri.startsWith(ModelerCore.XML_SCHEMA_GENERAL_URI)
        || uri.startsWith(ModelerCore.XML_XSD_GENERAL_URI)) return true;

    // If the URI is in the form of an Eclipse platform path to
    // one of the Emf XMLSchema resources ...
    if (uri.startsWith(
        XML_SCHEMA_ECLIPSE_PLATFORM_URI_PREFIX)) // MagicXMLSchema.xsd suffix on the resource URI
    if (uri.indexOf(XML_MAGIC_SCHEMA_ECLIPSE_PLATFORM_URI_SUFFIX) > 0) return true;
      else if (uri.indexOf(XML_SCHEMA_ECLIPSE_PLATFORM_URI_SUFFIX) > 0) return true;
      else if (uri.indexOf(XML_SCHEMA_INSTANCE_ECLIPSE_PLATFORM_URI_SUFFIX) > 0) return true;

    // Next check if the import reference is to one of our system models
    try {
      final Resource[] systemModels = ModelerCore.getSystemVdbResources();
      for (int i = 0; i != systemModels.length; ++i) {
        final String systemModelUri = URI.decode(systemModels[i].getURI().toString());
        if (uri.equalsIgnoreCase(systemModelUri)) return true;
      }
    } catch (final Exception e) {
      // do nothing
    }

    // Next check if the import reference is to one of our metamodels
    try {
      if (ModelerCore.getMetamodelRegistry().containsURI(uri)) return true;
    } catch (final Exception e) {
      // do nothing
    }

    // MyCode : 18565
    if (isLocalResource(uri)) return false;

    return false;
  }
コード例 #5
0
 static {
   if (ModelerCore.getPlugin() != null) {
     Resource[] systemModels = ModelerCore.getSystemVdbResources();
     systemModelByNameMap = new HashMap(systemModels.length);
     for (int i = 0; i != systemModels.length; ++i) {
       String name = systemModels[i].getURI().trimFileExtension().lastSegment();
       systemModelByNameMap.put(name.toUpperCase(), systemModels[i]);
     }
   }
 }
コード例 #6
0
  public static FacetValue getEnterpriseFacetValue(final XSDSimpleTypeDefinition startingType) {
    FacetValue fv = new FacetValue();

    final XSDSimpleTypeDefinition definingEnterpriseType = getDefiningEnterpriseType(startingType);
    fv.type = startingType;
    EnterpriseDatatypeInfo edi =
        ModelerCore.getWorkspaceDatatypeManager().getEnterpriseDatatypeInfo(definingEnterpriseType);
    fv.value = edi.getRuntimeType();

    if (startingType == definingEnterpriseType) {
      // this "facet" set in the specified type, so it is not default.
      // check parent for real default:
      final XSDSimpleTypeDefinition dftDefiner =
          getDefiningEnterpriseType(definingEnterpriseType.getBaseTypeDefinition());
      EnterpriseDatatypeInfo ediDft =
          ModelerCore.getWorkspaceDatatypeManager().getEnterpriseDatatypeInfo(dftDefiner);
      fv.defaultValue = ediDft.getRuntimeType();
      // set a fake facet to allow inherited checks to work:
      fv.facet =
          new XSDConstrainingFacetImpl() {
            @Override
            public String getFacetName() {
              return "This is not a real facet!"; //$NON-NLS-1$
            }

            @Override
            public XSDConcreteComponent getContainer() {
              return dftDefiner;
            }
          }; // endanon
    } else {
      // facet set by a parent, so it is default:
      fv.defaultValue = fv.value;
      // set a fake facet to allow inherited checks to work:
      fv.facet =
          new XSDConstrainingFacetImpl() {
            @Override
            public String getFacetName() {
              return "This is not a real facet!"; //$NON-NLS-1$
            }

            @Override
            public XSDConcreteComponent getContainer() {
              return definingEnterpriseType;
            }
          }; // endanon
    } // endif

    Boolean rtFixed = edi.getRuntimeTypeFixed();
    if (rtFixed != null) {
      fv.isFixedLocal = rtFixed.booleanValue();
    } // endif -- fixed null

    return fv;
  }
コード例 #7
0
  /**
   * @see
   *     org.teiid.designer.core.validation.ObjectValidationRule#validate(org.eclipse.emf.ecore.EObject,
   *     org.teiid.designer.core.validation.ValidationContext)
   * @since 4.2
   */
  @Override
  public void validate(final EObject eObject, final ValidationContext context) {
    CoreArgCheck.isNotNull(context);
    CoreArgCheck.isNotNull(eObject);

    // get uniqueness preference status
    final int status =
        context.getPreferenceStatus(ValidationPreferences.EOBJECT_UUID_UNIQUENESS, IStatus.ERROR);
    if (status == IStatus.OK) {
      return;
    }

    // if the eObject is a model annotation then
    // is already being validation by ModelAnnoattionUuidRule
    if (eObject instanceof ModelAnnotation) {
      return;
    }

    final ModelEditor editor = ModelerCore.getModelEditor();
    final String uuidString = ModelerCore.getObjectIdString(eObject);
    if (uuidString == null) {
      final String pathInModel = editor.getModelRelativePathIncludingModel(eObject).toString();
      final ValidationResult result = new ValidationResultImpl(eObject);
      // create validation problem and add it to the result
      final ValidationProblem problem =
          new ValidationProblemImpl(
              0,
              IStatus.ERROR,
              ModelerCore.Util.getString("EObjectUuidRule.0", pathInModel)); // $NON-NLS-1$
      problem.setHasPreference(context.hasPreferences());
      result.addProblem(problem);
      context.addResult(result);
    } else {
      boolean isDuplicate = context.containsUuid(uuidString);
      if (isDuplicate) {
        final String pathInModel = editor.getModelRelativePathIncludingModel(eObject).toString();
        final ValidationResult result = new ValidationResultImpl(eObject);
        String modelName = editor.getModelName(eObject);
        // create validation problem and addit to the result
        final ValidationProblem problem =
            new ValidationProblemImpl(
                0,
                status,
                ModelerCore.Util.getString(
                    "EObjectUuidRule.1", pathInModel, uuidString, modelName)); // $NON-NLS-1$
        problem.setHasPreference(context.hasPreferences());
        result.addProblem(problem);
        context.addResult(result);
      } else {
        context.addUuidToContext(uuidString);
      }
    }
  }
コード例 #8
0
 /* (non-Javadoc)
  * @See org.teiid.designer.core.workspace.ModelWorkspace#findModelResource(org.eclipse.emf.ecore.EObject)
  */
 @Override
 public ModelResource findModelResource(final EObject eObject) {
   CoreArgCheck.isNotNull(eObject);
   try {
     final Container container = ModelerCore.getModelContainer();
     Resource resource = ModelerCore.getModelEditor().findResource(container, eObject, false);
     if (resource != null) {
       return findModelResource(resource);
     }
   } catch (CoreException err) {
     ModelerCore.Util.log(err);
   }
   return null;
 }
コード例 #9
0
  public List getToolTipStrings() {
    List returnList = new ArrayList();
    if (isOnCoarseMappingDiagram()) {
      if (getExtent().getMappingReference() instanceof StagingTable) {
        String stName = ModelerCore.getModelEditor().getName(getExtent().getMappingReference());
        returnList.add(sStagingTablePrefix + stName);
      } else if (getExtent().getMappingReference() != null) {
        String stName = ModelerCore.getModelEditor().getName(getExtent().getMappingReference());
        returnList.add(sMappingClassPrefix + stName);
      } else {
        // handle Unmapped extents
        returnList.add("(unmapped)"); // $NON-NLS-1$
      }
      if (getExtent().getDocumentNodeReference() != null) {
        addToolTipStringsForLocation(returnList, getExtent());
      }
    } else {
      if (getExtent() != null) {
        if (getExtent().getMappingReference() instanceof StagingTable) {
          String stName = ModelerCore.getModelEditor().getName(getExtent().getMappingReference());
          returnList.add(sStagingTablePrefix + stName);
        } else {
          String stName = ModelerCore.getModelEditor().getName(super.getModelObject());
          returnList.add(sNamePrefix + stName);
          String sType =
              ModelerCore.getMetamodelRegistry().getMetaClassLabel(super.getModelObject().eClass());
          returnList.add(sTypePrefix + sType);

          returnList.add(sPathInDocumentPrefix + getExtent().getPathToDocumentRoot());

          String sComp = getExtent().getXsdQualifiedName();
          if (sComp == null || sComp.trim().length() == 0) {
            sComp = sNone;
            returnList.add(sXsdComponentPrefix + sComp);
          } else {
            returnList.add(sXsdComponentPrefix);
            String sNamespace = getExtent().getXsdTargetNamespace();
            if (sNamespace == null || sNamespace.trim().length() == 0) sNamespace = sNone;
            returnList.add(threeSpaces + sTargetNamespace + sNamespace);
            returnList.add(threeSpaces + sQualifiedName + sComp);
          }

          stName = "" + getExtent().isMappingRequired(); // $NON-NLS-1$
          returnList.add(sMappingRequiredPrefix + stName);
        }
      }
    }
    return returnList;
  }
コード例 #10
0
  /**
   * Creates a {@link MappingRoot} having the specified <code>MappingClass</code> as it's input.
   *
   * @param theMappingClass the <code>MappingClass</code> used to create the mapping root
   * @return the index in the <code>mappingRoots</code> list of the new root
   * @throws IllegalArgumentException if input parameter is <code>null</code>
   */
  public EObject createTreeMappingRoot(MappingClass theMappingClass) {
    // startTracking("createTreeMappingRoot(GENERATING)"); //$NON-NLS-1$

    CoreArgCheck.isNotNull(theMappingClass);
    if (mappingLocator.hasTreeRoot(theMappingClass)) {
      return mappingLocator.getMappingRoot(theMappingClass);
    }

    TreeMappingRoot newRoot = null;
    try {
      // Defect 18433 - BML 8/31/05 - Changed call to create tree mapping root using a new
      // utility method that correctly adds it to the model (via addValue()) and also performs
      // additional work (i.e.adding nested Sql Helpers.
      newRoot =
          ModelResourceContainerFactory.createNewTreeMappingRoot(this.root, this.root.eResource());

      // Now add the mapping class to the Inputs list of the tree mapping root
      ModelerCore.getModelEditor().addValue(newRoot, theMappingClass, newRoot.getInputs());

    } catch (Exception theException) {
      Util.log(
          IStatus.ERROR,
          theException,
          Util.getString(
              PREFIX + "createMappingRootProblem", // $NON-NLS-1$
              new Object[] {root, theMappingClass}));
    }

    // stopTracking("createTreeMappingRoot(GENERATING)"); //$NON-NLS-1$
    return newRoot;
  }
コード例 #11
0
 /**
  * @see
  *     org.teiid.designer.core.container#isExternalResource(org.eclipse.emf.ecore.resource.Resource)
  * @since 4.3
  */
 @Override
 public boolean isExternalResource(final Resource theResource) {
   if (theResource != null && ModelerCore.getContainer(theResource) == getContainer()) {
     return false;
   }
   return true;
 }
コード例 #12
0
 /**
  * @see org.teiid.designer.core.workspace.ModelWorkspace#createModelProject(java.lang.String,
  *     java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
  * @since 4.0
  */
 @Override
 public ModelProject createModelProject(
     final String name, final IPath path, final IProgressMonitor monitor) throws CoreException {
   CoreArgCheck.isNotNull(name);
   // Check if project already exists
   if (findModelProject(name) != null) {
     throw new ModelWorkspaceException(
         ModelerCore.Util.getString(
             "ModelWorkspaceImpl.cannotCreateModelProject", name)); // $NON-NLS-1$
   }
   // Validate name
   final IWorkspace workspace = ModelerCore.getWorkspace();
   final IStatus status = workspace.validateName(name, IResource.PROJECT);
   if (!status.isOK()) {
     throw new ModelWorkspaceException(
         new ModelStatusImpl(status.getSeverity(), status.getCode(), status.getMessage()));
   }
   // Create new model project
   final IProject project = workspace.getRoot().getProject(name);
   final IProjectDescription desc = workspace.newProjectDescription(project.getName());
   desc.setLocation(path);
   desc.setNatureIds(MODEL_NATURES);
   final IWorkspaceRunnable op =
       new IWorkspaceRunnable() {
         @Override
         public void run(final IProgressMonitor monitor) throws CoreException {
           project.create(desc, monitor);
           project.open(monitor);
         }
       };
   workspace.run(op, monitor);
   return new ModelProjectImpl(project, this);
 }
コード例 #13
0
  @Override
  public ModelWorkspaceItem getParent(final IResource resource) {
    CoreArgCheck.isNotNull(resource);

    IProject project = resource.getProject();
    if (project.isAccessible() && !ModelerCore.hasModelNature(project)) {
      return null;
    }

    // If the resource is an IProject... return the resource
    if (resource instanceof IProject) {
      return this;
    }

    // If the parent is null, return null
    final IResource parent = resource.getParent();
    if (parent == null) {
      return null;
    }

    // Calculate the parent path from the given resource
    final IPath path = resource.getFullPath();
    final IPath parentPath = path.removeLastSegments(1);

    // Find the workspaceItem for the parent path1
    return getWorkspaceItem(parentPath);
  }
コード例 #14
0
 public static void removeFacet(XSDSimpleTypeDefinition type, XSDConstrainingFacet facet) {
   try {
     ModelerCore.getModelEditor().removeValue(type, facet, type.getFacetContents());
   } catch (ModelerCoreException err) {
     ModelerXsdUiConstants.Util.log(err);
   } // endtry
 }
コード例 #15
0
 public static void setEnterpriseFacetValue(XSDSimpleTypeDefinition type, FacetValue newValue) {
   if (newValue.value != null) {
     // set new enterprise info:
     EnterpriseDatatypeInfo edi =
         ModelerCore.getWorkspaceDatatypeManager().getEnterpriseDatatypeInfo(type);
     if (edi == null) {
       edi = new EnterpriseDatatypeInfo();
     } // endif
     edi.setRuntimeTypeFixed(new Boolean(newValue.isFixedLocal));
     edi.setRuntimeType((String) newValue.value);
     ModelEditorImpl.fillWithDefaultValues(edi, type);
     ModelerCore.getModelEditor().setEnterpriseDatatypePropertyValue(type, edi);
   } else {
     // need to unset:
     ModelerCore.getModelEditor().unsetEnterpriseDatatypePropertyValue(type);
   } // endif
 }
コード例 #16
0
  /**
   * Find the EObject having the specified UUID using the ObjectManager for the lookup. If an
   * EObject with this UUID cannot be found then null is returned.
   */
  protected EObject lookupEObject(final String uuid) {
    CoreArgCheck.isNotEmpty(uuid);

    // Before searching by UUID make sure all resources associated with this QMI are loaded
    if (this.getResources() != null) {
      for (Iterator iter = this.getResources().iterator(); iter.hasNext(); ) {
        Resource r = (Resource) iter.next();
        if (!r.isLoaded()) {
          try {
            r.load(Collections.EMPTY_MAP);
          } catch (IOException e) {
            TransformationPlugin.Util.log(IStatus.ERROR, e.getLocalizedMessage());
          }
        }
      }
    }

    // Go to the Container ...
    EObject eObject = null;

    if (this.getContainer() != null) {
      eObject = (EObject) this.getContainer().getEObjectFinder().find(uuid);

      if (eObject != null) {
        // get the resource on the object
        Resource resource = eObject.eResource();
        // check if this is among the resources is scope for this QMI
        if (this.getResources() != null) {
          Container cntr = ModelerCore.getContainer(resource);
          // If the resource exists in the same Container as the one associated with this QMI
          // but the resource is not in the scope of resources then return null
          if (cntr == this.getContainer() && !this.getResources().contains(resource)) {
            return null;
          }
        }
      }
      return eObject;
    }

    // We are in a non-container environment
    Iterator rsrs = this.getResources().iterator();
    while (rsrs.hasNext()) {
      Resource rsrc = (Resource) rsrs.next();
      if (rsrc instanceof MMXmiResource) {
        eObject = ((MMXmiResource) rsrc).getEObject(uuid);
        if (eObject != null) {
          return eObject;
        }
      } else if (rsrc instanceof XSDResourceImpl) {
        eObject = ((XSDResourceImpl) rsrc).getEObject(uuid);
        if (eObject != null) {
          return eObject;
        }
      }
    }

    return eObject;
  }
コード例 #17
0
 /** @see DatatypeFinder#findDatatype(java.lang.String) */
 @Override
 public EObject findDatatype(final String name) throws CoreException {
   final DatatypeManager dtMgr =
       ModelerCore.getWorkspaceDatatypeManager(); // only care about built-ins!
   if (name == null) {
     return dtMgr.getAnySimpleType();
   }
   final EObject datatype = dtMgr.getBuiltInDatatype(name);
   return datatype;
 }
コード例 #18
0
 /** @see DatatypeFinder#findDatatype(org.eclipse.emf.common.util.URI) */
 @Override
 public EObject findDatatype(final URI uri) throws CoreException {
   final DatatypeManager dtMgr =
       ModelerCore.getWorkspaceDatatypeManager(); // only care about built-ins!
   if (uri == null) {
     return dtMgr.getAnySimpleType();
   }
   final EObject datatype = dtMgr.findDatatype(uri.toString());
   return datatype;
 }
コード例 #19
0
  private void executeInTransaction(final Resource resource, final Shell shell) {
    boolean requiredStart =
        ModelerCore.startTxn(true, true, "Update Cost Statistics", this); // $NON-NLS-1$
    boolean succeeded = false;
    try {
      internalExecute(resource, shell);

      succeeded = true;
    } finally {
      // if we started the txn, commit it.
      if (requiredStart) {
        if (succeeded) {
          ModelerCore.commitTxn();
        } else {
          ModelerCore.rollbackTxn();
        }
      }
    }
  }
コード例 #20
0
 /** Compute the non-java resources contained in this java project. */
 private Object[] computeNonModelResources() {
   IProject[] projects = ModelerCore.getWorkspace().getRoot().getProjects();
   int length = projects.length;
   Object[] nonModelResourcesTemp = null;
   int index = 0;
   for (int i = 0; i < length; i++) {
     IProject project = projects[i];
     if (!ModelerCore.hasModelNature(project)) {
       if (nonModelResourcesTemp == null) {
         nonModelResourcesTemp = new Object[length];
       }
       nonModelResourcesTemp[index++] = project;
     }
   }
   if (index == 0) return NO_NON_MODEL_RESOURCES;
   if (index < length) {
     System.arraycopy(nonModelResources, 0, nonModelResources = new Object[index], 0, index);
   }
   return nonModelResourcesTemp;
 }
コード例 #21
0
 /**
  * Validates the destination file if it is read-only and additionally the source file if both are
  * read-only. Returns true if both files could be made writeable.
  *
  * @param source source file
  * @param destination destination file
  * @param shell ui context for the validation
  * @return boolean <code>true</code> both files could be made writeable. <code>false</code> either
  *     one or both files were not made writeable
  */
 boolean validateEdit(IFile source, IFile destination, Shell shell) {
   if (destination.isReadOnly()) {
     IWorkspace workspace = ModelerCore.getWorkspace();
     IStatus status;
     if (source.isReadOnly())
       status = workspace.validateEdit(new IFile[] {source, destination}, shell);
     else status = workspace.validateEdit(new IFile[] {destination}, shell);
     return status.isOK();
   }
   return true;
 }
コード例 #22
0
  /**
   * @see
   *     org.teiid.designer.core.validation.ObjectValidationRule#validate(org.eclipse.emf.ecore.EObject,
   *     org.teiid.designer.core.validation.ValidationContext)
   * @since 4.2
   */
  @Override
  public void validate(final EObject eObject, final ValidationContext context) {
    CoreArgCheck.isNotNull(context);
    CoreArgCheck.isInstanceOf(ModelAnnotation.class, eObject);

    final ModelEditor editor = ModelerCore.getModelEditor();
    String uuidString = ModelerCore.getObjectIdString(eObject);
    if (uuidString == null) {
      final String pathInModel = editor.getModelRelativePathIncludingModel(eObject).toString();
      final ValidationResult result = new ValidationResultImpl(eObject);
      // create validation problem and add it to the result
      final ValidationProblem problem =
          new ValidationProblemImpl(
              0,
              IStatus.ERROR,
              ModelerCore.Util.getString("ModelAnnotationUuidRule.0", pathInModel)); // $NON-NLS-1$
      result.addProblem(problem);
      context.addResult(result);
    } else {
      boolean isDuplicate = context.containsUuid(uuidString);
      if (isDuplicate) {
        final String pathInModel = editor.getModelRelativePathIncludingModel(eObject).toString();
        final ValidationResult result = new ValidationResultImpl(eObject);
        String modelName = editor.getModelName(eObject);
        // create validation problem and addit to the result
        final ValidationProblem problem =
            new ValidationProblemImpl(
                0,
                IStatus.ERROR,
                ModelerCore.Util.getString(
                    "ModelAnnotationUuidRule.1",
                    pathInModel,
                    uuidString,
                    modelName)); //$NON-NLS-1$
        result.addProblem(problem);
        context.addResult(result);
      } else {
        context.addUuidToContext(uuidString);
      }
    }
  }
コード例 #23
0
  private String getUndoText(EObject[] selectedObjects) {

    String description = null;
    if (selectedObjects.length == 1) {
      EObject obj = selectedObjects[0];
      String path = ModelerCore.getModelEditor().getModelRelativePath(obj).toString();
      description = UiConstants.Util.getString(UNDO_TEXT, path);
    } else {
      description = UiConstants.Util.getString(PLURAL_UNDO_TEXT, selectedObjects.length);
    }
    return description;
  }
コード例 #24
0
 /**
  * Return a reference to a {@link QueryMetadataInterface} implementation that for the given
  * eObject , its resourceand the resources that depend ont it. This assumes the Eobject is in a
  * modelContainer, should be used only for workspace validation.
  *
  * @param eObject The eObject for which metadata instance is returned
  * @param restrictSearch A boolean indicating if the search needs to be restricted to model
  *     imports or if the whole workspace needs to be searched
  * @return the QueryMetadataInterface implementation; never null
  */
 public QueryMetadataInterface getModelerMetadata(
     final EObject eObject, final boolean restrictSearch) {
   CoreArgCheck.isNotNull(eObject);
   QueryMetadataContext context = buildQueryMetadataContext(eObject, restrictSearch);
   Container container = null;
   try {
     container = ModelerCore.getModelContainer();
   } catch (CoreException e) {
     TransformationPlugin.Util.log(e);
   }
   return getModelerMetadata(context, container);
 }
コード例 #25
0
  /* (non-Javadoc)
   * @See org.teiid.designer.ui.wizards.INewModelWizardContributor#doFinish(org.teiid.designer.core.workspace.ModelResource, org.eclipse.core.runtime.IProgressMonitor)
   */
  @Override
  public void doFinish(ModelResource modelResource, IProgressMonitor monitor) {
    String transactionName =
        Util.getString("TransformationLinkContributor.transactionName"); // $NON-NLS-1$
    boolean started = ModelerCore.startTxn(transactionName, this);
    boolean succeeded = false;
    try {
      IStructuralCopyTreePopulator populator = transformationLinkPage.getTreePopulator();
      TreeViewer viewer = transformationLinkPage.getViewer();
      Map extraProperties =
          transformationLinkPage.isClearSupportsUpdate()
              ? MAP_CLEAR_SUPPORTS_UPDATES
              : MAP_KEEP_SUPPORTS_UPDATES;
      if ((populator != null) && (viewer != null)) {

        // all nodes selected, copy all:
        populator.copyModel(
            (ModelResource) viewer.getInput(),
            modelResource,
            extraProperties,
            transformationLinkPage.isCopyAllDescriptions(),
            monitor);
      }
      succeeded = true;
    } catch (Exception ex) {
      String message =
          UiConstants.Util.getString(
              "TransformationLinkContributor.doFinishError", //$NON-NLS-1$
              modelResource.getItemName());
      UiConstants.Util.log(IStatus.ERROR, ex, message);
    } finally {
      if (started) {
        if (succeeded) {
          ModelerCore.commitTxn();
        } else {
          ModelerCore.rollbackTxn();
        }
      }
    }
  }
コード例 #26
0
  public static XSDConstrainingFacet addOrSetFacetValue(
      XSDSimpleTypeDefinition type, String facetName, FacetValue fv) {
    XSDConstrainingFacet workFacet = fv.facet;
    // do we need to add?
    if (fv.facet == null || fv.facet.getContainer() != type) {
      // need to add to this type:
      boolean inclusiveness = false;
      if (fv.value instanceof InclusiveInteger) {
        inclusiveness = ((InclusiveInteger) fv.value).isInclusive;
      } // endif

      // remove any facets with opposite inclusiveness:
      if (facetName == FAKE_FACET_MAXIMUM || facetName == FAKE_FACET_MINIMUM) {
        // go ahead and remove:
        removeFacet(type, facetName);
      } // endif -- using fake facets?

      workFacet = createFacet(facetName, inclusiveness);

      try {
        ModelerCore.getModelEditor().addValue(type, workFacet, type.getFacetContents());
      } catch (ModelerCoreException err) {
        ModelerXsdUiConstants.Util.log(err);
      } // endtry
    } // endif

    // set main value:
    if (!FormUtil.safeEquals(fv.value, getMainFacetValue(workFacet))) {
      // only set if changed:
      workFacet = setMainFacetValue(type, workFacet, fv.value);
      // in case this is a bounds facet and we swapped them out:
      fv.facet = workFacet;
    } // endif

    // set description:
    String existingDesc = ModelObjectUtilities.getDescription(workFacet);
    if (fv.description != null) {
      // new not null:
      if (!fv.description.equals(existingDesc)) {
        // description changed to a nonnull value:
        ModelObjectUtilities.setDescription(workFacet, fv.description, type);
      } // endif -- different
    } else if (existingDesc != null && existingDesc.length() > 0) {
      // new null, old not null:
      ModelObjectUtilities.setDescription(workFacet, " ", type); // $NON-NLS-1$
    } // endif

    // Lastly, set fixed if applicable:
    setFixed(workFacet, fv.isFixedLocal);

    return workFacet;
  }
コード例 #27
0
  /**
   * @param location the XSDSchema object to add this type to.
   * @param typeName the name to give the newly created type.
   * @param baseType (optional) if not null, use this type as the base type of the new type.
   * @return
   */
  public static XSDSimpleTypeDefinition createAtomicSimpleTypeDefinintion(
      XSDSchema location, String typeName, XSDSimpleTypeDefinition baseType) {
    XSDSimpleTypeDefinition std =
        (XSDSimpleTypeDefinition)
            XSDFactory.eINSTANCE.create(XSDPackage.eINSTANCE.getXSDSimpleTypeDefinition());
    std.setName(typeName);
    // defect 18444 - make sure things are wrapped in transactions
    try {
      ModelerCore.getModelEditor().addValue(location, std, location.getContents());

      if (baseType != null) {
        ModelerCore.getDatatypeManager(std).setBasetypeDefinition(std, baseType);
      } else {
        XSDSimpleTypeDefinition defaultBaseType = getDefaultBaseType();
        ModelerCore.getDatatypeManager(std).setBasetypeDefinition(std, defaultBaseType);
      } // endif
    } catch (ModelerCoreException ex) {
      ModelerXsdUiConstants.Util.log(ex);
    } // endtry

    return std;
  }
コード例 #28
0
  @Override
  protected IProgressMonitor executeCommand(final RefactorCommand command) {
    IProgressMonitor monitor = super.executeCommand(command);

    try {
      // Save refactored resource
      final ModelEditor editor = ModelerCore.getModelEditor();

      // defect 16527 - check that a resource is a file before casting
      IResource res = this.dest.findMember(MoveRefactorAction.this.resSelectedResource.getName());
      if (res instanceof IFile) {
        final IFile file = (IFile) res;
        ModelResource model = editor.findModelResource(file);
        if (model != null) {
          if (model.getEmfResource().isModified()) {
            // If an editor is open, call doSave on it, else tell the model to save
            org.teiid.designer.ui.editors.ModelEditor openEditor =
                ModelEditorManager.getModelEditorForFile(file, false);
            if (openEditor != null) {
              openEditor.doSave(monitor);
            } else {
              model.save(monitor, true);
            }
          }
        }
      } // endif -- move was on a file

      // Save modified dependent resources
      for (final Iterator iter = ((ResourceMoveCommand) command).getDependentResources().iterator();
          iter.hasNext(); ) {
        IFile file = (IFile) iter.next();
        ModelResource model = editor.findModelResource(file);
        if (model != null) {
          if (model.getEmfResource().isModified() && !model.isReadOnly()) {
            // If an editor is open, call doSave on it, else tell the model to save
            org.teiid.designer.ui.editors.ModelEditor openEditor =
                ModelEditorManager.getModelEditorForFile(file, false);
            if (openEditor != null) {
              openEditor.doSave(monitor);
            } else {
              model.save(monitor, true);
            }
          }
        }
      }
    } catch (final ModelWorkspaceException err) {
      ModelerCore.Util.log(err);
    }

    return monitor;
  }
コード例 #29
0
  /**
   * Create a Model with the supplied name, in the desired project
   *
   * @param targetProj the project resource under which to create the model
   * @param modelName the model name to create
   * @return the newly-created ModelResource
   */
  public ModelResource constructModel(IResource targetRes, String sModelName) {

    String sFileName = getFileName(sModelName);
    IPath relativeModelPath = targetRes.getProjectRelativePath().append(sFileName);
    final IFile modelFile = targetRes.getProject().getFile(relativeModelPath);
    final ModelResource resrc = ModelerCore.create(modelFile);
    try {
      resrc.getModelAnnotation().setPrimaryMetamodelUri(newModelInfo.getModelURI());
      resrc.getModelAnnotation().setModelType(newModelInfo.getModelType());
    } catch (ModelWorkspaceException mwe) {
      mwe.printStackTrace();
    }
    return resrc;
  }
コード例 #30
0
  void handleViewModelLocationBrowse() {
    final IContainer folder =
        WidgetUtil.showFolderSelectionDialog(
            ModelerCore.getWorkspace().getRoot(),
            new ModelingResourceFilter(),
            new ModelProjectSelectionStatusValidator());

    if (folder != null && sourceModelContainerText != null) {
      // viewModelContainerText.setText(folder.getFullPath().makeRelative().toString());
      this.importManager.setViewModelLocation(folder);
      this.viewModelContainerText.setText(folder.getFullPath().makeRelative().toString());
    }

    notifyChanged();
  }